<?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/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://rubensargsyan.com</link>
	<description>Personal Website</description>
	<lastBuildDate>Fri, 27 Aug 2010 07:08:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<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[PHP]]></category>
		<category><![CDATA[jQuery]]></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 script useful to you, please consider making a small donation to assist in further development contribution. Thanks for your kind support!</p>
<form style="padding: 0px, margin: 0px" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_donations">
<input type="hidden" name="business" value="roobensargsyan@gmail.com">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="item_name" value="Ruben Sargsyan">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="bn" value="PP-DonationsBF:btn_donate_LG.gif:NonHostedGuest">
<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_donate_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"><br />
</form>
]]></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>Tags of the file content</title>
		<link>http://rubensargsyan.com/tags-of-the-file-content/</link>
		<comments>http://rubensargsyan.com/tags-of-the-file-content/#comments</comments>
		<pubDate>Mon, 01 Feb 2010 18:54:47 +0000</pubDate>
		<dc:creator>Ruben Sargsyan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[tags]]></category>

		<guid isPermaLink="false">http://rubensargsyan.com/?p=261</guid>
		<description><![CDATA[This function is used for leading out all tags with their counts from the file. &#60;?php function tags_in_the_file&#40;$file&#41;&#123; if&#40;file_exists&#40;$file&#41;&#41;&#123; $content = file_get_contents&#40;$file, true&#41;; &#160; preg_match_all&#40;&#34;/(&#60;([\w]+)[^&#62;]*&#62;)/&#34;, $content, $matches, PREG_SET_ORDER&#41;; &#160; $tags = array&#40;&#41;; $tags_count = 0; &#160; foreach&#40;$matches as $tag&#41;&#123; $tag_found = false; &#160; if&#40;!empty&#40;$tags&#41;&#41;&#123; for&#40;$i=0; $i&#60;count&#40;$tags&#41;; $i++&#41;&#123; if&#40;$tags&#91;$i&#93;&#91;&#34;tag&#34;&#93;==$tag&#91;2&#93;&#41;&#123; $tags&#91;$i&#93;&#91;&#34;count&#34;&#93;++; $tag_found = true; break; &#125; &#125; [...]]]></description>
			<content:encoded><![CDATA[<p>This function is used for leading out all tags with their counts from the file.<span id="more-261"></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> tags_in_the_file<span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</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;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <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: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</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;([\w]+)[^&gt;]*&gt;)/&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: #000088;">$tags</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;">$tags_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;">$matches</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$tag</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$tag_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;">$tags</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;">$tags</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;">$tags</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;tag&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span><span style="color: #000088;">$tag</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                        <span style="color: #000088;">$tags</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;">$tag_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;">$tag_found</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$tags</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$tags_count</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;tag&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$tag</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$tags</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$tags_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;">$tags_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;">$tag_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>
&nbsp;
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$tags</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: #000088;">$file</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;test.html&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$tags</span> <span style="color: #339933;">=</span> tags_in_the_file<span style="color: #009900;">&#40;</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: #000088;">$tags</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;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tags</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$tag</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;">$tag</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;tag&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; - &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$tag</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: #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: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;File not found!&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>

<p>the test.html content:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">html</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">title</span>&gt;</span>Tags of the file content<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">title</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">span</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;hello&quot;</span>&gt;</span>Hello<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;</span> <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">span</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;world&quot;</span>&gt;</span>world<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;</span>.
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>My personal website is <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://rubensargsyan.com&quot;</span>&gt;</span>http://rubensargsyan.com<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</span></pre></div></div>

<p>Output:</p>
<p>html &#8211; 1</p>
<p>head &#8211; 1</p>
<p>title &#8211; 1</p>
<p>body &#8211; 1</p>
<p>span &#8211; 2</p>
<p>p &#8211; 1</p>
<p>a &#8211; 1</p>
<hr />
<p>If the file is not found the function return false.</p>
]]></content:encoded>
			<wfw:commentRss>http://rubensargsyan.com/tags-of-the-file-content/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>0</slash:comments>
		</item>
		<item>
		<title>Send message to the emails included in the file</title>
		<link>http://rubensargsyan.com/send-message-to-the-emails-included-in-the-file/</link>
		<comments>http://rubensargsyan.com/send-message-to-the-emails-included-in-the-file/#comments</comments>
		<pubDate>Mon, 23 Nov 2009 17:39:38 +0000</pubDate>
		<dc:creator>Ruben Sargsyan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[email]]></category>

		<guid isPermaLink="false">http://rubensargsyan.com/?p=112</guid>
		<description><![CDATA[This function is used for sending message to the emails included in the file text. &#60;?php function send_message_to_emails_included_in_file&#40;$file,$subject,$message,$headers=&#34;&#34;, $parameters=&#34;&#34;&#41;&#123; if&#40;file_exists&#40;$file&#41;&#41;&#123; $content = file_get_contents&#40;$file, true&#41;; preg_match_all&#40;'/(\w+\.)*\w+@(\w+\.)*\w+(\w+\-\w+)*\.\w+/', $content, $emails, PREG_PATTERN_ORDER&#41;; &#160; $emails = $emails&#91;0&#93;; $emails = array_unique&#40;$emails&#41;; &#160; foreach&#40;$emails as $email&#41;&#123; mail&#40;$email,$subject,$message,$headers,$parameters&#41;; &#125; return true; &#125;else&#123; return false; &#125; &#125; &#160; $file = &#34;file.txt&#34;; // the path [...]]]></description>
			<content:encoded><![CDATA[<p>This function is used for sending message to the emails included in the file text.<span id="more-112"></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> send_message_to_emails_included_in_file<span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #339933;">,</span><span style="color: #000088;">$subject</span><span style="color: #339933;">,</span><span style="color: #000088;">$message</span><span style="color: #339933;">,</span><span style="color: #000088;">$headers</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$parameters</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: #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: #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: #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;">preg_match_all</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/(\w+\.)*\w+@(\w+\.)*\w+(\w+\-\w+)*\.\w+/'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span><span style="color: #339933;">,</span> <span style="color: #000088;">$emails</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;">$emails</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$emails</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;">$emails</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_unique</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$emails</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;">$emails</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$email</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
         <span style="color: #990000;">mail</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$email</span><span style="color: #339933;">,</span><span style="color: #000088;">$subject</span><span style="color: #339933;">,</span><span style="color: #000088;">$message</span><span style="color: #339933;">,</span><span style="color: #000088;">$headers</span><span style="color: #339933;">,</span><span style="color: #000088;">$parameters</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</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: #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: #000088;">$file</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;file.txt&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// the path of the file</span>
<span style="color: #000088;">$subject</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Hello&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// email subject</span>
<span style="color: #000088;">$message</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;This is a test message.&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// email massage</span>
<span style="color: #000088;">$headers</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;From: rubensargsyan.com&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// email headers</span>
&nbsp;
send_message_to_emails_included_in_file<span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #339933;">,</span><span style="color: #000088;">$subject</span><span style="color: #339933;">,</span><span style="color: #000088;">$message</span><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: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>If the file is not found the function return false.</p>
]]></content:encoded>
			<wfw:commentRss>http://rubensargsyan.com/send-message-to-the-emails-included-in-the-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Highlight words in a text</title>
		<link>http://rubensargsyan.com/highlight-words-in-a-text/</link>
		<comments>http://rubensargsyan.com/highlight-words-in-a-text/#comments</comments>
		<pubDate>Fri, 20 Nov 2009 11:11:49 +0000</pubDate>
		<dc:creator>Ruben Sargsyan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[highlight]]></category>

		<guid isPermaLink="false">http://rubensargsyan.com/?p=98</guid>
		<description><![CDATA[This function is used to search and highlight words from the text. function highlight_words&#40;$text,$word&#41;&#123; $text = preg_replace&#40;'/\b'.$word.'\b/i', '&#60;span class=&#34;highlight&#34;&#62;$0&#60;/span&#62;', $text&#41;; return $text; &#125; Note to that if the searched word is in the structure of the other wordform (for example the word &#8220;stand&#8221; is in the structure of the word &#8220;understand&#8221;), so the word will [...]]]></description>
			<content:encoded><![CDATA[<p>This function is used to search and highlight words from the text.<span id="more-98"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> highlight_words<span style="color: #009900;">&#40;</span><span style="color: #000088;">$text</span><span style="color: #339933;">,</span><span style="color: #000088;">$word</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: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/\b'</span><span style="color: #339933;">.</span><span style="color: #000088;">$word</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'\b/i'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;span class=&quot;highlight&quot;&gt;$0&lt;/span&gt;'</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: #b1b100;">return</span> <span style="color: #000088;">$text</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Note to that if the searched word is in the structure of the other wordform (for example the word &#8220;stand&#8221; is in the structure of the word &#8220;understand&#8221;), so the word will not be highlighted. It will be highlighted when  after  or  before  the  word  is  not  appeared alphabetic or digital character  or underline (_) character. The function also ignores case sensitivity of the word. If the searched word is &#8220;light&#8221;, the words  &#8220;highlight&#8221;,  &#8220;light_faced&#8221;,  &#8220;lighten&#8221;, &#8220;light9&#8243; e.t.c. will not be highlighted as well.</p>
<h2>Example:</h2>
<p>Searching the word &#8220;book&#8221; in the text &#8220;Our book-keeper was bought an interesting book from bookshop. Book name is My big book.&#8221;</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> highlight_words<span style="color: #009900;">&#40;</span><span style="color: #000088;">$text</span><span style="color: #339933;">,</span><span style="color: #000088;">$word</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: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/\b'</span><span style="color: #339933;">.</span><span style="color: #000088;">$word</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'\b/i'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;span class=&quot;highlight&quot;&gt;$0&lt;/span&gt;'</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;">return</span> <span style="color: #000088;">$text</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
&lt;style&gt;
.highlight{
   background-color: #214579;
   color: #ffffff;
}
&lt;/style&gt;
&nbsp;
<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;book&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$text</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Our book-keeper was bought an interesting book from bookshop. Book name is My big book.&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">echo</span><span style="color: #009900;">&#40;</span>highlight_words<span style="color: #009900;">&#40;</span><span style="color: #000088;">$text</span><span style="color: #339933;">,</span><span style="color: #000088;">$word</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></pre></div></div>

<p>The above example will output:</p>
<p>Our <span style="background-color: #214579; color: #ffffff;">book</span>-keeper was bought an interesting <span style="background-color: #214579; color: #ffffff;">book</span> from bookshop. <span style="background-color: #214579; color: #ffffff;">Book</span> name is My big <span style="background-color: #214579; color: #ffffff;">book</span>.</p>
<p>You   see   that   the  word  &#8220;book&#8221;  of  the  wordform  &#8220;bookshop&#8221;  was not highlighted, and the words &#8220;book-keeper&#8221;, &#8220;book&#8221;, &#8220;Book&#8221; and &#8220;book&#8221; which is followed by  the punctuation mark &#8220;.&#8221; was highlighted.</p>
<p>Set your style to the highlighted words in .highlight{ &#8230; }.</p>
<p>The demo you can see <a href="http://rubensargsyan.com/demo/highlight_words" target="_blank">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://rubensargsyan.com/highlight-words-in-a-text/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
