<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ruben Sargsyan &#187; PHP</title>
	<atom:link href="http://rubensargsyan.com/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://rubensargsyan.com</link>
	<description>Personal Website</description>
	<lastBuildDate>Thu, 03 May 2012 21:02:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Generate YouTube video browser-based uploading form by PHP</title>
		<link>http://rubensargsyan.com/generate-youtube-video-browser-based-uploading-form-by-php/</link>
		<comments>http://rubensargsyan.com/generate-youtube-video-browser-based-uploading-form-by-php/#comments</comments>
		<pubDate>Wed, 02 Feb 2011 18:09:28 +0000</pubDate>
		<dc:creator>Ruben Sargsyan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[YouTube]]></category>

		<guid isPermaLink="false">http://rubensargsyan.com/?p=575</guid>
		<description><![CDATA[Here is an example how to generate YouTube video browser-based uploading form by PHP: &#60;?php $youtube_email = &#34;example@youtube.com&#34;; // Change this to your youtube sign in email. $youtube_password = &#34;password&#34;; // Change this to your youtube sign in password. &#160; $postdata = &#34;Email=&#34;.$youtube_email.&#34;&#38;Passwd=&#34;.$youtube_password.&#34;&#38;service=youtube&#38;source=Example&#34;; $curl = curl_init&#40;&#34;https://www.google.com/youtube/accounts/ClientLogin&#34;&#41;; curl_setopt&#40;$curl, CURLOPT_HEADER, &#34;Content-Type:application/x-www-form-urlencoded&#34;&#41;; curl_setopt&#40;$curl, CURLOPT_POST, 1&#41;; curl_setopt&#40;$curl, CURLOPT_POSTFIELDS, $postdata&#41;; [...]]]></description>
			<content:encoded><![CDATA[<p>Here is an example how to generate YouTube video browser-based uploading form by PHP:<span id="more-575"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$youtube_email</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;example@youtube.com&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Change this to your youtube sign in email.</span>
<span style="color: #000088;">$youtube_password</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;password&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Change this to your youtube sign in password.</span>
&nbsp;
<span style="color: #000088;">$postdata</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Email=&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$youtube_email</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&amp;Passwd=&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$youtube_password</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&amp;service=youtube&amp;source=Example&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$curl</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;https://www.google.com/youtube/accounts/ClientLogin&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_HEADER<span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Content-Type:application/x-www-form-urlencoded&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_POST<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_POSTFIELDS<span style="color: #339933;">,</span> <span style="color: #000088;">$postdata</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_SSL_VERIFYPEER<span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_SSL_VERIFYHOST<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$response</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">list</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$auth</span><span style="color: #339933;">,</span> <span style="color: #000088;">$youtubeuser</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$response</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">list</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$authlabel</span><span style="color: #339933;">,</span> <span style="color: #000088;">$authvalue</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_map</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;trim&quot;</span><span style="color: #339933;">,</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;=&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$auth</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">list</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$youtubeuserlabel</span><span style="color: #339933;">,</span> <span style="color: #000088;">$youtubeuservalue</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_map</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;trim&quot;</span><span style="color: #339933;">,</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;=&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$youtubeuser</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$youtube_video_title</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Example&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// This is the uploading video title.</span>
<span style="color: #000088;">$youtube_video_description</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Example&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// This is the uploading video description.</span>
<span style="color: #000088;">$youtube_video_category</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;News&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// This is the uploading video category.</span>
<span style="color: #000088;">$youtube_video_keywords</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;example, video&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// This is the uploading video keywords.</span>
&nbsp;
<span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;?xml version=&quot;1.0&quot;?&gt;
            &lt;entry xmlns=&quot;http://www.w3.org/2005/Atom&quot;
              xmlns:media=&quot;http://search.yahoo.com/mrss/&quot;
              xmlns:yt=&quot;http://gdata.youtube.com/schemas/2007&quot;&gt;
              &lt;media:group&gt;
                &lt;media:title type=&quot;plain&quot;&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$youtube_video_title</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/media:title&gt;
                &lt;media:description type=&quot;plain&quot;&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$youtube_video_description</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/media:description&gt;
                &lt;media:category
                  scheme=&quot;http://gdata.youtube.com/schemas/2007/categories.cat&quot;&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$youtube_video_category</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/media:category&gt;
                &lt;media:keywords&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$youtube_video_keywords</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/media:keywords&gt;
              &lt;/media:group&gt;
            &lt;/entry&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$key</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;adf15ee97731bca89da876c...a8dc&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Get your key here: http://code.google.com/apis/youtube/dashboard/.</span>
&nbsp;
<span style="color: #000088;">$headers</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Authorization: GoogleLogin auth=&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$authvalue</span><span style="color: #339933;">,</span>
                 <span style="color: #0000ff;">&quot;GData-Version: 2&quot;</span><span style="color: #339933;">,</span>
                 <span style="color: #0000ff;">&quot;X-GData-Key: key=&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$key</span><span style="color: #339933;">,</span>
                 <span style="color: #0000ff;">&quot;Content-length: &quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                 <span style="color: #0000ff;">&quot;Content-Type: application/atom+xml; charset=UTF-8&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$curl</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://gdata.youtube.com/action/GetUploadToken&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_USERAGENT<span style="color: #339933;">,</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;HTTP_USER_AGENT&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_TIMEOUT<span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_SSL_VERIFYPEER<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_POST<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_FOLLOWLOCATION<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_HTTPHEADER<span style="color: #339933;">,</span> <span style="color: #000088;">$headers</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_POSTFIELDS<span style="color: #339933;">,</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_REFERER<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_FOLLOWLOCATION<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_HEADER<span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$response</span> <span style="color: #339933;">=</span> <span style="color: #990000;">simplexml_load_string</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;script type=&quot;text/javascript&quot;&gt;
  function checkForFile() {
    if (document.getElementById('file').value) {
      return true;
    }
    document.getElementById('errMsg').style.display = '';
    return false;
  }
&lt;/script&gt;
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$nexturl</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://rubensargsyan.com&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// This parameter specifies the URL to which YouTube will redirect the user's browser when the user uploads his video file.</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
&lt;form action=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$response</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>?nexturl=<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$nexturl</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; method=&quot;post&quot; enctype=&quot;multipart/form-data&quot; onsubmit=&quot;return checkForFile();&quot;&gt;
  &lt;input id=&quot;file&quot; type=&quot;file&quot; name=&quot;file&quot;/&gt;
  &lt;div id=&quot;errMsg&quot; style=&quot;display:none;color:red&quot;&gt;
    You need to specify a file.
  &lt;/div&gt;
  &lt;input type=&quot;hidden&quot; name=&quot;token&quot; value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$response</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">token</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;/&gt;
  &lt;input type=&quot;submit&quot; value=&quot;go&quot; /&gt;
&nbsp;
&lt;/form&gt;
&lt;/php&gt;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://rubensargsyan.com/generate-youtube-video-browser-based-uploading-form-by-php/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Retrieve links and sort them by follow or nofollow</title>
		<link>http://rubensargsyan.com/retrieve-links-and-sort-them-by-follow-or-nofollow/</link>
		<comments>http://rubensargsyan.com/retrieve-links-and-sort-them-by-follow-or-nofollow/#comments</comments>
		<pubDate>Tue, 16 Nov 2010 11:50:14 +0000</pubDate>
		<dc:creator>Ruben Sargsyan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[follow links]]></category>
		<category><![CDATA[links]]></category>
		<category><![CDATA[nofollow links]]></category>
		<category><![CDATA[sort]]></category>

		<guid isPermaLink="false">http://rubensargsyan.com/?p=475</guid>
		<description><![CDATA[This PHP example is used to retrieve all links from a file content or a url content, then sort by the follow links or nofollow links and show them: &#60;?php $file = &#34;http://example.com&#34;; &#160; $content = file_get_contents&#40;$file&#41;; $links = array&#40;&#34;follow&#34;=&#62;array&#40;&#41;,&#34;nofollow&#34;=&#62;array&#40;&#41;&#41;; &#160; preg_match_all&#40;&#34;/(&#60;a.*&#62;)(.*)(&#60;\/a&#62;)/ismU&#34;,$content,$matches,PREG_SET_ORDER&#41;; &#160; if&#40;empty&#40;$matches&#41;&#41;&#123; echo&#40;&#34;There is no link in the file &#34;.$file.&#34;.&#34;&#41;; &#125;else&#123; foreach&#40;$matches as [...]]]></description>
			<content:encoded><![CDATA[<p>This PHP example is used to retrieve all links from a file content or a url content, then sort by the follow links or nofollow links and show them<span id="more-475"></span>:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$file</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://example.com&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$links</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;follow&quot;</span><span style="color: #339933;">=&gt;</span>array<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;nofollow&quot;</span><span style="color: #339933;">=&gt;</span>array<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">preg_match_all</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/(&lt;a.*&gt;)(.*)(&lt;\/a&gt;)/ismU&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$content</span><span style="color: #339933;">,</span><span style="color: #000088;">$matches</span><span style="color: #339933;">,</span>PREG_SET_ORDER<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$matches</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;There is no link in the file &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$file</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$matches</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$match</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/href\s*=\s*[\'|<span style="color: #000099; font-weight: bold;">\&quot;</span>]\s*([^<span style="color: #000099; font-weight: bold;">\&quot;</span>|\']*)\s*[\'|<span style="color: #000099; font-weight: bold;">\&quot;</span>]/i&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$match</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #000088;">$href</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/rel\s*=\s*[\'|<span style="color: #000099; font-weight: bold;">\&quot;</span>]\s*nofollow\s*[\'|<span style="color: #000099; font-weight: bold;">\&quot;</span>]/i&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$match</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$links</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;nofollow&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$href</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$links</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;follow&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$href</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000088;">$output</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&lt;h1&gt;Nofollow links&lt;/h1&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$links</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;nofollow&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;There is no nofollow link.&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;ol type='1'&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$links</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;nofollow&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$link</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;li&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$link</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/li&gt;&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;/ol&gt;&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;h1&gt;Follow links&lt;/h1&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$links</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;follow&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;There is no follow link.&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;ol type='1'&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$links</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;follow&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$link</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;li&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$link</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/li&gt;&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;/ol&gt;&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #b1b100;">echo</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$output</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://rubensargsyan.com/retrieve-links-and-sort-them-by-follow-or-nofollow/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Sort all words and write into a file</title>
		<link>http://rubensargsyan.com/sort-all-words-and-write-into-a-file/</link>
		<comments>http://rubensargsyan.com/sort-all-words-and-write-into-a-file/#comments</comments>
		<pubDate>Mon, 04 Oct 2010 07:03:40 +0000</pubDate>
		<dc:creator>Ruben Sargsyan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[sort]]></category>
		<category><![CDATA[text]]></category>
		<category><![CDATA[words]]></category>

		<guid isPermaLink="false">http://rubensargsyan.com/?p=410</guid>
		<description><![CDATA[A PHP example to sort all words of a text in alphabetical order and write the words into a file. &#60;?php function sort_all_words_and_write_into_file&#40;$text,$file&#41;&#123; preg_match_all&#40;&#34;/[a-z0-9_\-]+/i&#34;,$text,$matches,PREG_PATTERN_ORDER&#41;; &#160; $matches = array_unique&#40;$matches&#91;0&#93;&#41;; &#160; natcasesort&#40;$matches&#41;; &#160; $file_content = &#34;&#34;; &#160; while&#40;current&#40;$matches&#41;&#41;&#123; $file_content .= current&#40;$matches&#41;; &#160; if&#40;next&#40;$matches&#41;&#41;&#123; $file_content .= &#34;\r\n&#34;; &#125; &#125; &#160; if&#40;file_exists&#40;$file&#41;&#41;&#123; if&#40;is_writable&#40;$file&#41;&#41;&#123; if&#40;file_put_contents&#40;$file,$file_content&#41;&#41;&#123; return true; &#125; &#125; &#125;else&#123; [...]]]></description>
			<content:encoded><![CDATA[<p>A PHP example to sort all words of a text in alphabetical order and write the words into a file<span id="more-410"></span>.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">function</span> sort_all_words_and_write_into_file<span style="color: #009900;">&#40;</span><span style="color: #000088;">$text</span><span style="color: #339933;">,</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #990000;">preg_match_all</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/[a-z0-9_\-]+/i&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$text</span><span style="color: #339933;">,</span><span style="color: #000088;">$matches</span><span style="color: #339933;">,</span>PREG_PATTERN_ORDER<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$matches</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_unique</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$matches</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #990000;">natcasesort</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$matches</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$file_content</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">current</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$matches</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$file_content</span> <span style="color: #339933;">.=</span> <span style="color: #990000;">current</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$matches</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">next</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$matches</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$file_content</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">is_writable</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">file_put_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #339933;">,</span><span style="color: #000088;">$file_content</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">file_put_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #339933;">,</span><span style="color: #000088;">$file_content</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$text</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;A PHP example to sort all words of a text in alphabetical order and write the words into a file.&quot;</span><span style="color: #339933;">;</span>
&nbsp;
sort_all_words_and_write_into_file<span style="color: #009900;">&#40;</span><span style="color: #000088;">$text</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;file.txt&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>The function returns false if the words haven&#8217;t been written into the file.</p>
]]></content:encoded>
			<wfw:commentRss>http://rubensargsyan.com/sort-all-words-and-write-into-a-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automatically put words for autocompleting</title>
		<link>http://rubensargsyan.com/automatically-put-words-for-autocompleting/</link>
		<comments>http://rubensargsyan.com/automatically-put-words-for-autocompleting/#comments</comments>
		<pubDate>Fri, 25 Jun 2010 11:30:27 +0000</pubDate>
		<dc:creator>Ruben Sargsyan</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[autocomplete]]></category>
		<category><![CDATA[automatically]]></category>
		<category><![CDATA[texts]]></category>

		<guid isPermaLink="false">http://rubensargsyan.com/?p=384</guid>
		<description><![CDATA[While I was looking through a site about migrate sharepoint, I saw a search field with autocompleting and the first idea I have is to develop a code that will automatically put those words for autocompleting that are more often happen in the texts. &#60;?php function get_words&#40;$texts&#41;&#123; if&#40;!empty&#40;$texts&#41;&#41;&#123; $words = array&#40;&#41;; $words_count = 0; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>While I was looking through a site about <a href="http://www.itransition.com/sharepoint/" target="_blank">migrate sharepoint</a>, I saw a search field with autocompleting and the first idea I have is to develop a code that will automatically put those words for autocompleting that are more often happen in the texts<span id="more-384"></span>.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">function</span> get_words<span style="color: #009900;">&#40;</span><span style="color: #000088;">$texts</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$texts</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$words</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$words_count</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$texts</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$text</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #990000;">preg_match_all</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/\w{2,}/i&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$text</span><span style="color: #339933;">,</span> <span style="color: #000088;">$matches</span><span style="color: #339933;">,</span> PREG_SET_ORDER<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$matches</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$word</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$word_found</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$words</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                    <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">&lt;</span>count<span style="color: #009900;">&#40;</span><span style="color: #000088;">$words</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$words</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;word&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span><span style="color: #000088;">$word</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                            <span style="color: #000088;">$words</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;count&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">++;</span>
                            <span style="color: #000088;">$word_found</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
                            <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
                        <span style="color: #009900;">&#125;</span>
                    <span style="color: #009900;">&#125;</span>
                <span style="color: #009900;">&#125;</span>
&nbsp;
                <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$word_found</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                    <span style="color: #000088;">$words</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$words_count</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;word&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$word</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                    <span style="color: #000088;">$words</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$words_count</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;count&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
&nbsp;
                    <span style="color: #000088;">$words_count</span><span style="color: #339933;">++;</span>
                <span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
                    <span style="color: #000088;">$word_found</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$words</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> sort_by_words_count<span style="color: #009900;">&#40;</span><span style="color: #000088;">$word1</span><span style="color: #339933;">,</span><span style="color: #000088;">$word2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$word1_count</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$word1</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;count&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$word2_count</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$word2</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;count&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$word1_count</span><span style="color: #339933;">&lt;</span><span style="color: #000088;">$word2_count</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #b1b100;">elseif</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$word1_count</span><span style="color: #339933;">==</span><span style="color: #000088;">$word2_count</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$text1</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;If you would like to have your running line on your Wordpress blog, so this plugin is just for you! It gives you the possibility to show one of the posts from your chosen category by the running line. So download and enjoy!&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$text2</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;This plugin is used when there are words, words expressions or sentences to be explained in the posts or pages of your wordpress blog. This plugin will help the visitors to read the explanations of the words (words expressions,sentences) you need via tooltips.&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$text3</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Any occasion to receive greetings? So, this plugin is just for you! This Widget plugin shows a greeting image which would be uploaded for the occasion and a pop up form for receiving the greetings. It is possible to show the greetings in any post or page.&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$text4</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;This plugin adds links after the posts for subscribing to the post author's posts feed via RSS. So if there are several authors in the blog, but a visitor wishes to subscribe just an author posts feed, this plugin gives that possibility to do it.&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$text5</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;This is a widget plugin which helps to display the visitors who left the most number of comments in the Wordpress blog.&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$texts</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$text1</span><span style="color: #339933;">,</span> <span style="color: #000088;">$text2</span><span style="color: #339933;">,</span> <span style="color: #000088;">$text3</span><span style="color: #339933;">,</span> <span style="color: #000088;">$text4</span><span style="color: #339933;">,</span> <span style="color: #000088;">$text4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$all_words</span> <span style="color: #339933;">=</span> get_words<span style="color: #009900;">&#40;</span><span style="color: #000088;">$texts</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">usort</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$all_words</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'sort_by_words_count'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$autocompleting_words_count</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Autocompleting words count</span>
&nbsp;
<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">&lt;</span><span style="color: #000088;">$autocompleting_words_count</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$autocompleting_words</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$all_words</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;word&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$autocompleting_words</span> <span style="color: #339933;">=</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;,&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$autocompleting_words</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
&lt;html&gt;
&lt;head&gt;
  &lt;link href=&quot;http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;/&gt;
  &lt;script src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js&quot;&gt;&lt;/script&gt;
  &lt;script src=&quot;http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js&quot;&gt;&lt;/script&gt;
&nbsp;
  &lt;script&gt;
  $(document).ready(function() {
    $(&quot;input#autocomplete&quot;).autocomplete({
    source: [<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$autocompleting_words</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>]
});
  });
  &lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&nbsp;
&lt;input id=&quot;autocomplete&quot; /&gt;
&nbsp;
&lt;/body&gt;
&lt;/html&gt;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://rubensargsyan.com/automatically-put-words-for-autocompleting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Move JavaScript codes from a file to an other file</title>
		<link>http://rubensargsyan.com/move-javascript-codes-from-a-file-to-an-other-file/</link>
		<comments>http://rubensargsyan.com/move-javascript-codes-from-a-file-to-an-other-file/#comments</comments>
		<pubDate>Wed, 26 May 2010 09:06:26 +0000</pubDate>
		<dc:creator>Ruben Sargsyan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[matching]]></category>

		<guid isPermaLink="false">http://rubensargsyan.com/?p=365</guid>
		<description><![CDATA[An example to move the JavaScript codes from a file to an other file: &#60;?php function moveJavascriptCodes&#40;$fromFile,$toFile&#41;&#123; $fileText = file_get_contents&#40;$fromFile&#41;; &#160; preg_match_all&#40;&#34;#&#60;script\b[^&#62;]*&#62;(.*?)&#60;/script&#62;#si&#34;,$fileText,$javascriptCodes,PREG_SET_ORDER&#41;; &#160; $codes = array&#40;&#41;; &#160; foreach&#40;$javascriptCodes as $javascriptCode&#41;&#123; $codes&#91;&#93; = $javascriptCode&#91;1&#93;; &#125; &#160; if&#40;file_put_contents&#40;$toFile,implode&#40;&#34;\n&#34;,$codes&#41;&#41;===false&#41;&#123; return false; &#125; &#160; return true; &#125; &#160; $fromFile = &#34;totalCode.php&#34;; //The file from which JavaScript code will be [...]]]></description>
			<content:encoded><![CDATA[<p>An example to move the JavaScript codes from a file to an other file:<span id="more-365"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">function</span> moveJavascriptCodes<span style="color: #009900;">&#40;</span><span style="color: #000088;">$fromFile</span><span style="color: #339933;">,</span><span style="color: #000088;">$toFile</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$fileText</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fromFile</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #990000;">preg_match_all</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#&lt;script\b[^&gt;]*&gt;(.*?)&lt;/script&gt;#si&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$fileText</span><span style="color: #339933;">,</span><span style="color: #000088;">$javascriptCodes</span><span style="color: #339933;">,</span>PREG_SET_ORDER<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$codes</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$javascriptCodes</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$javascriptCode</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$codes</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$javascriptCode</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">file_put_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$toFile</span><span style="color: #339933;">,</span><span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$codes</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">===</span><span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$fromFile</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;totalCode.php&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//The file from which JavaScript code will be got</span>
<span style="color: #000088;">$toFile</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;javascriptCode.js&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//The file into which JavaScript code will be set</span>
&nbsp;
moveJavascriptCodes<span style="color: #009900;">&#40;</span><span style="color: #000088;">$fromFile</span><span style="color: #339933;">,</span><span style="color: #000088;">$toFile</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://rubensargsyan.com/move-javascript-codes-from-a-file-to-an-other-file/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Search text in the directory files</title>
		<link>http://rubensargsyan.com/search-text-in-the-directory-files/</link>
		<comments>http://rubensargsyan.com/search-text-in-the-directory-files/#comments</comments>
		<pubDate>Wed, 31 Mar 2010 07:51:49 +0000</pubDate>
		<dc:creator>Ruben Sargsyan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[search]]></category>
		<category><![CDATA[text]]></category>

		<guid isPermaLink="false">http://rubensargsyan.com/?p=324</guid>
		<description><![CDATA[An example for searching text (a word or phrase) in the directory files: &#60;?php function search_text_in_directory_files&#40;$directory, $text&#41;&#123; if&#40;file_exists&#40;$directory&#41;&#41;&#123; $files = array&#40;&#41;; &#160; if&#40;$handle=opendir&#40;$directory&#41;&#41;&#123; while&#40;&#40;$file=readdir&#40;$handle&#41;&#41;!==false&#41;&#123; if&#40;$file!=&#34;.&#34; &#38;&#38; $file!=&#34;..&#34; &#38;&#38; !is_dir&#40;$directory.&#34;/&#34;.$file&#41; &#38;&#38; file_exists&#40;$directory.&#34;/&#34;.$file&#41;&#41;&#123; $file_content = file_get_contents&#40;$directory.&#34;/&#34;.$file&#41;; &#160; if&#40;preg_match&#40;&#34;/&#34;.$text.&#34;/i&#34;,$file_content&#41;&#41;&#123; $files&#91;&#93; = $file; &#125; &#125; &#125; closedir&#40;$handle&#41;; &#125; &#160; return $files; &#125; &#160; return false; &#125; &#160; $directory = [...]]]></description>
			<content:encoded><![CDATA[<p>An example for searching text (a word or phrase) in the directory files:<span id="more-324"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">function</span> search_text_in_directory_files<span style="color: #009900;">&#40;</span><span style="color: #000088;">$directory</span><span style="color: #339933;">,</span> <span style="color: #000088;">$text</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$directory</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$files</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #339933;">=</span><span style="color: #990000;">opendir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$directory</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #339933;">=</span><span style="color: #990000;">readdir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">!==</span><span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #339933;">!=</span><span style="color: #0000ff;">&quot;.&quot;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$file</span><span style="color: #339933;">!=</span><span style="color: #0000ff;">&quot;..&quot;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span><span style="color: #990000;">is_dir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$directory</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$directory</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                    <span style="color: #000088;">$file_content</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$directory</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$text</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/i&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$file_content</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                        <span style="color: #000088;">$files</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$file</span><span style="color: #339933;">;</span>
                    <span style="color: #009900;">&#125;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #990000;">closedir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$files</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$directory</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;files&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$text</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;text&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$found_files</span> <span style="color: #339933;">=</span> search_text_in_directory_files<span style="color: #009900;">&#40;</span><span style="color: #000088;">$directory</span><span style="color: #339933;">,</span><span style="color: #000088;">$text</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$found_files</span><span style="color: #339933;">===</span><span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Directory Not Found&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #b1b100;">elseif</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$found_files</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Text Not Found&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$found_files</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$found_file</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;p&gt;<span style="color: #006699; font-weight: bold;">$found_file</span>&lt;/p&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://rubensargsyan.com/search-text-in-the-directory-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Grayscale</title>
		<link>http://rubensargsyan.com/grayscale/</link>
		<comments>http://rubensargsyan.com/grayscale/#comments</comments>
		<pubDate>Sat, 20 Mar 2010 13:50:50 +0000</pubDate>
		<dc:creator>Ruben Sargsyan</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Grayscale]]></category>
		<category><![CDATA[image manipulation]]></category>

		<guid isPermaLink="false">http://rubensargsyan.com/?p=318</guid>
		<description><![CDATA[This is an image manipulation script that makes the selected photos grayscale and in the case of mouseover the colors are restored. It is easy to use, just put &#8220;grayscale&#8221; as the classes of the images. It used PHP and JavaScript for developing the script. How To Use: 1. Include grayscale.js: &#60;script src=&#8221;grayscale/grayscale.js&#8221; type=&#8221;text/javascript&#8221;&#62;&#60;/script&#62; 2. [...]]]></description>
			<content:encoded><![CDATA[<p>This is an image manipulation script that makes the selected photos grayscale and in the case of mouseover the colors are restored. It is easy to use, just put &#8220;grayscale&#8221; as the classes of the images. It used PHP and JavaScript for developing the script.<span id="more-318"></span></p>
<h2>How To Use:</h2>
<p>1. Include grayscale.js:</p>
<div style="color: #993300">&lt;script src=&#8221;grayscale/grayscale.js&#8221; type=&#8221;text/javascript&#8221;&gt;&lt;/script&gt;</div>
<p>2. Put &#8220;grayscale&#8221; as the classes of the images.</p>
<h2>Demo:</h2>
<p><a href="http://rubensargsyan.com/demo/grayscale/" target="_blank">Demo</a></p>
<h2>Version:</h2>
<p>1.0</p>
<h2>License:</h2>
<p><a rel="license" href="http://creativecommons.org/licenses/by/3.0/us/"><img alt="Creative Commons License" style="border-width:0" src="http://i.creativecommons.org/l/by/3.0/us/88x31.png" /></a><br /><span xmlns:dc="http://purl.org/dc/elements/1.1/" href="http://purl.org/dc/dcmitype/Text" property="dc:title" rel="dc:type">Grayscale</span> by <a xmlns:cc="http://creativecommons.org/ns#" href="http://rubensargsyan.com/" property="cc:attributionName" rel="cc:attributionURL">Ruben Sargsyan</a> is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by/3.0/us/">Creative Commons Attribution 3.0 United States License</a>.<br />Based on a work at <a xmlns:dc="http://purl.org/dc/elements/1.1/" href="http://rubensargsyan.com/grayscale/" rel="dc:source">rubensargsyan.com</a>.</p>
<h2>Download:</h2>
<p><a href="http://rubensargsyan.com/downloads/grayscale.zip">From rubensargsyan.com</a></p>
<h2>Donate:</h2>
<p>If you find this plugin useful to you, please consider making a small donation to help contribute to further development. Thanks for your kind support!<br />
<a href="http://rubensargsyan.com/donate/"><img src="https://www.paypal.com/en_US/i/btn/btn_donate_LG.gif" border="0" alt="Donate" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://rubensargsyan.com/grayscale/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sort texts by matching the word</title>
		<link>http://rubensargsyan.com/sort-texts-by-matching-the-word/</link>
		<comments>http://rubensargsyan.com/sort-texts-by-matching-the-word/#comments</comments>
		<pubDate>Mon, 15 Feb 2010 12:01:04 +0000</pubDate>
		<dc:creator>Ruben Sargsyan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[matching]]></category>
		<category><![CDATA[sort]]></category>
		<category><![CDATA[texts]]></category>

		<guid isPermaLink="false">http://rubensargsyan.com/?p=274</guid>
		<description><![CDATA[An example for sorting texts in array by matching the word in them: &#60;?php $word = &#34;plugin&#34;; &#160; function sort_by_matching_word&#40;$text1,$text2&#41;&#123; global $word; &#160; $text1_matched_words_count = preg_match&#40;&#34;/\b&#34;.$word.&#34;\b/i&#34;,$text1&#41;; $text2_matched_words_count = preg_match&#40;&#34;/\b&#34;.$word.&#34;\b/i&#34;,$text2&#41;; &#160; if&#40;$text1_matched_words_count&#60;$text2_matched_words_count&#41;&#123; return 1; &#125;elseif&#40;$text1_matched_words_count==$text2_matched_words_count&#41;&#123; return 0; &#125;else&#123; return -1; &#125; &#125; &#160; $wordpress_plugin_running_line = &#34;If you would like to have your running line on your [...]]]></description>
			<content:encoded><![CDATA[<p>An example for sorting texts in array by matching the word in them:<span id="more-274"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$word</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;plugin&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> sort_by_matching_word<span style="color: #009900;">&#40;</span><span style="color: #000088;">$text1</span><span style="color: #339933;">,</span><span style="color: #000088;">$text2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$word</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000088;">$text1_matched_words_count</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/\b&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$word</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;\b/i&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$text1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$text2_matched_words_count</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/\b&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$word</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;\b/i&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$text2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$text1_matched_words_count</span><span style="color: #339933;">&lt;</span><span style="color: #000088;">$text2_matched_words_count</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #b1b100;">elseif</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$text1_matched_words_count</span><span style="color: #339933;">==</span><span style="color: #000088;">$text2_matched_words_count</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$wordpress_plugin_running_line</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;If you would like to have your running line on your Wordpress blog, so this plugin is just for you! It gives you the possibility to show one of the posts from your chosen category by the running line. So download and enjoy!&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$wordpress_plugin_explanatory_dictionary</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;This plugin is used when there are words, words expressions or sentences to be explained in the posts or pages of your wordpress blog. This plugin will help the visitors to read the explanations of the words (words expressions,sentences) you need via tooltips.&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$wordpress_plugin_greetings</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Any occasion to receive greetings? So, this plugin is just for you! This Widget plugin shows a greeting image which would be uploaded for the occasion and a pop up form for receiving the greetings. It is possible to show the greetings in any post or page.&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$my_plugins</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$wordpress_plugin_running_line</span><span style="color: #339933;">,</span><span style="color: #000088;">$wordpress_plugin_explanatory_dictionary</span><span style="color: #339933;">,</span><span style="color: #000088;">$wordpress_plugin_greetings</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">usort</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$my_plugins</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'sort_by_matching_word'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$my_plugins</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$my_plugin</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;p&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$my_plugin</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/p&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://rubensargsyan.com/sort-texts-by-matching-the-word/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Select matching words from two texts</title>
		<link>http://rubensargsyan.com/select-matching-words-from-two-texts/</link>
		<comments>http://rubensargsyan.com/select-matching-words-from-two-texts/#comments</comments>
		<pubDate>Thu, 24 Dec 2009 08:04:58 +0000</pubDate>
		<dc:creator>Ruben Sargsyan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[matching words]]></category>

		<guid isPermaLink="false">http://rubensargsyan.com/?p=223</guid>
		<description><![CDATA[This function returns matching words array from two texts or returns false in case of not matching any words. &#60;?php function strings_intersect_words&#40;$str1,$str2&#41;&#123; $str1 = trim&#40;$str1&#41;; $str2 = trim&#40;$str2&#41;; &#160; $str1_words = explode&#40;&#34; &#34;,$str1&#41;; $str2_words = explode&#40;&#34; &#34;,$str2&#41;; &#160; $str1_words = array_unique&#40;$str1_words&#41;; $str2_words = array_unique&#40;$str2_words&#41;; &#160; $intersect_words = array&#40;&#41;; &#160; foreach&#40;$str1_words as $str1_word&#41;&#123; if&#40;array_search&#40;$str1_word,$str2_words&#41;!==false &#38;&#38; trim&#40;$str1_word&#41;!=&#34;&#34;&#41;&#123; [...]]]></description>
			<content:encoded><![CDATA[<p>This function returns matching words array from two texts or returns false in case of not matching any words.<span id="more-223"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">function</span> strings_intersect_words<span style="color: #009900;">&#40;</span><span style="color: #000088;">$str1</span><span style="color: #339933;">,</span><span style="color: #000088;">$str2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$str1</span> <span style="color: #339933;">=</span> <span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$str1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$str2</span> <span style="color: #339933;">=</span> <span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$str2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$str1_words</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$str1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$str2_words</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$str2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$str1_words</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_unique</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$str1_words</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$str2_words</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_unique</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$str2_words</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$intersect_words</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$str1_words</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$str1_word</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array_search</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$str1_word</span><span style="color: #339933;">,</span><span style="color: #000088;">$str2_words</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">!==</span><span style="color: #009900; font-weight: bold;">false</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$str1_word</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">!=</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$intersect_words</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$str1_word</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$intersect_words</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$intersect_words</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$str1</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;I am Ruben Sargsyan from Armenia. I am a web developer.&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$str2</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://rubensargsyan.com is a web developer Ruben Sargsyan's personal website.&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$intersect_words</span> <span style="color: #339933;">=</span> strings_intersect_words<span style="color: #009900;">&#40;</span><span style="color: #000088;">$str1</span><span style="color: #339933;">,</span><span style="color: #000088;">$str2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$intersect_words</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Output:</p>
<p>Array ( [0] => Ruben [1] => a [2] => web )</p>
]]></content:encoded>
			<wfw:commentRss>http://rubensargsyan.com/select-matching-words-from-two-texts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Write rss to a file</title>
		<link>http://rubensargsyan.com/write-rss-to-a-file/</link>
		<comments>http://rubensargsyan.com/write-rss-to-a-file/#comments</comments>
		<pubDate>Mon, 07 Dec 2009 13:00:56 +0000</pubDate>
		<dc:creator>Ruben Sargsyan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[RSS]]></category>
		<category><![CDATA[file]]></category>

		<guid isPermaLink="false">http://rubensargsyan.com/?p=178</guid>
		<description><![CDATA[This function is used for writing rss to a file. &#60;?php function rss_to_file&#40;$url,$file&#41;&#123; $rss = simplexml_load_file&#40;$url&#41;; &#160; if&#40;$rss&#41;&#123; $text = &#34;&#34;; &#160; $text .= $rss-&#62;channel-&#62;title.&#34;\r\n \r\n \r\n&#34;; &#160; $items = $rss-&#62;channel-&#62;item; &#160; foreach&#40;$items as $item&#41;&#123; $title = $item-&#62;title; $link = $item-&#62;link; $published_on = $item-&#62;pubDate; $description = $item-&#62;description; &#160; $text .= $title.&#34;\r\n&#34;; $text .= $published_on.&#34;\r\n&#34;; $text [...]]]></description>
			<content:encoded><![CDATA[<p>This function is used for writing rss to a file.<span id="more-178"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">function</span> rss_to_file<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">,</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$rss</span> <span style="color: #339933;">=</span> <span style="color: #990000;">simplexml_load_file</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$rss</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$text</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$text</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$rss</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">channel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span> <span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span> <span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$items</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$rss</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">channel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$items</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$title</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$link</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">link</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$published_on</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">pubDate</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$description</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">description</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$text</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$title</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$text</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$published_on</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$text</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$description</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span> <span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000088;">$handle</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'w'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">fwrite</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #339933;">,</span> <span style="color: #000088;">$text</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://rubensargsyan.wordpress.com/feed/&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Rss url</span>
<span style="color: #000088;">$file</span> <span style="color: #339933;">=</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Y-m-d&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;.txt&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// The file</span>
&nbsp;
rss_to_file<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">,</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>If the rss url is wrong the function return false.</p>
]]></content:encoded>
			<wfw:commentRss>http://rubensargsyan.com/write-rss-to-a-file/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

