<?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; sort</title>
	<atom:link href="http://rubensargsyan.com/tag/sort/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>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>
	</channel>
</rss>
