<?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>Learn PHP programming</title>
	<atom:link href="http://www.mysqlphptutorial.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mysqlphptutorial.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Fri, 28 Aug 2009 09:34: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>strcmp &#8211; String Compare</title>
		<link>http://www.mysqlphptutorial.com/functions/strcmp-string-compare/</link>
		<comments>http://www.mysqlphptutorial.com/functions/strcmp-string-compare/#comments</comments>
		<pubDate>Tue, 18 Aug 2009 11:51:59 +0000</pubDate>
		<dc:creator>PHP HELP</dc:creator>
				<category><![CDATA[Functions]]></category>
		<category><![CDATA[strcasecmp()]]></category>
		<category><![CDATA[strcmp()]]></category>
		<category><![CDATA[strnatcasecmp()]]></category>
		<category><![CDATA[strnatcmo()]]></category>
		<category><![CDATA[strncasecmp()]]></category>
		<category><![CDATA[strncmp()]]></category>

		<guid isPermaLink="false">http://www.mysqlphptutorial.com/?p=93</guid>
		<description><![CDATA[Here are some of string comparation php functions: strcmp($s1, $s2) &#8211; returns 0 if $s1 and $s2 are equal, a negativ value (-1) if $s1$s2. The string comparation is case-sensitive, character by character, comparing character&#8217;s codes. Uppercase chars are considered smaller than minuscule chars. Numbers are considered smaller than letters. strcasecmp($s1, $s2) &#8211; idem, but [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p>Here are some of string comparation php functions:</p>
<ul>
<li><strong>strcmp</strong>($s1, $s2) &#8211; returns 0 if $s1 and $s2 are equal, a negativ value (-1) if $s1<$s2 and positive value (1) if $s1>$s2. The string comparation is case-sensitive, character by character, comparing character&#8217;s codes. Uppercase chars are considered smaller than minuscule chars. Numbers are considered smaller than letters.</li>
<li><strong>strcasecmp</strong>($s1, $s2) &#8211; idem, but the string compare is case-insensitive</li>
<li><strong>strncmp</strong>($s1, $s2, $nr) &#8211; like strcmp() but it compare only the first $nr chars of the 2 strings.</li>
<li><strong>strncasecmp</strong>($s1, $s2, $nr) &#8211; idem, case-insensitive</li>
<li><strong>strnatcmp</strong>($s1, $s2) &#8211; natural comparation, case-sensitive of the 2 strings (like natsort())</li>
<li><strong>strnatcasecmp</strong>($s1, $s2) &#8211; idem, but case-insensitive</li>
</ul>
<p><span id="more-93"></span></p>
<h2>String compare function examples</h2>
<div class="geshi no php">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">&lt;?php</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$s1</span> <span class="sy0">=</span> <span class="st0">&quot;1 Euro&quot;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$s2</span> <span class="sy0">=</span> <span class="st0">&quot;2 Euro&quot;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$s3</span> <span class="sy0">=</span> <span class="st0">&quot;10 Euro&quot;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$s4</span> <span class="sy0">=</span> <span class="st0">&quot;10 euro&quot;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">echo</span> <span class="kw3">strcmp</span><span class="br0">&#40;</span><span class="re1">$s1</span><span class="sy0">,</span> <span class="re1">$s2</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">// -1 ($s1 is alphabetically before $s2)</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">echo</span> <span class="kw3">strcmp</span><span class="br0">&#40;</span><span class="re1">$s3</span><span class="sy0">,</span> <span class="re1">$s4</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">// -1 (the code of E char is before e char)</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">echo</span> <span class="kw3">strcasecmp</span><span class="br0">&#40;</span><span class="re1">$s3</span><span class="sy0">,</span> <span class="re1">$s4</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">// 0 (case insensitive, the two strings are equal)</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">echo</span> <span class="kw3">strcmp</span><span class="br0">&#40;</span><span class="re1">$s2</span><span class="sy0">,</span> <span class="re1">$s3</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">// 1 (char 1 is before 2)</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">echo</span> <span class="kw3">strnatcmp</span><span class="br0">&#40;</span><span class="re1">$s2</span><span class="sy0">,</span> <span class="re1">$s3</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">// -1 (char 2 as number is before 10)</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">echo</span> <span class="kw3">strncmp</span><span class="br0">&#40;</span><span class="re1">$s1</span><span class="sy0">,</span> <span class="re1">$s4</span><span class="sy0">,</span> <span class="nu0">1</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">// 0 (comparing only the first char, there is equality)</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">?&gt;</span></div>
</li>
</ol>
</div>


<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.mysqlphptutorial.com/functions/strcmp-string-compare/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>strpos &#8211; Find the Position of a String</title>
		<link>http://www.mysqlphptutorial.com/functions/strpos-find-the-position-of-a-string/</link>
		<comments>http://www.mysqlphptutorial.com/functions/strpos-find-the-position-of-a-string/#comments</comments>
		<pubDate>Tue, 18 Aug 2009 11:03:21 +0000</pubDate>
		<dc:creator>PHP HELP</dc:creator>
				<category><![CDATA[Functions]]></category>
		<category><![CDATA[stripos()]]></category>
		<category><![CDATA[strpos()]]></category>
		<category><![CDATA[strripos()]]></category>
		<category><![CDATA[strrpos()]]></category>

		<guid isPermaLink="false">http://www.mysqlphptutorial.com/?p=83</guid>
		<description><![CDATA[Finding the position of a string or substring can be made with this php functions: strpos($string, $seached_string [,$offset]) &#8211; returns position of the first occurrence of $searched_string inside $string or FALSE if $searched_string is not found. If $offset is specified, the seach will be made starting with $offset position. stripos($string, $seached_string [,$offset]) &#8211; idem, but [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p>Finding the position of a string or substring can be made with this php functions:</p>
<ul>
<li><strong>strpos</strong>($string, $seached_string [,$offset]) &#8211; returns position of the first occurrence of $searched_string inside $string or FALSE if $searched_string is not found. If $offset is specified, the seach will be made starting with $offset position.</li>
<li><strong>stripos</strong>($string, $seached_string [,$offset]) &#8211; idem, but the search is case-insensitive</li>
<li><strong>strrpos</strong>($string, $seached_string [,$offset]) &#8211; returns the position of the last occurrence of $searched_string inside $string, or FALSE</li>
<li><strong>strripos</strong>($string, $seached_string [,$offset]) &#8211; idem with strrpos but is case-insensitive</li>
</ul>
<p><span id="more-83"></span></p>
<h2>Finding the position of a substring in string examples</h2>
<div class="geshi no php">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">&lt;?php</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$string</span> <span class="sy0">=</span> <span class="st0">&quot;Count of Monte Cristo&quot;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">echo</span> <span class="kw3">strpos</span><span class="br0">&#40;</span><span class="re1">$string</span><span class="sy0">,</span> <span class="st0">&quot;nt&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">// 3 (first occurrence of nt inside $string)</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">echo</span> <span class="kw3">strrpos</span><span class="br0">&#40;</span><span class="re1">$string</span><span class="sy0">,</span> <span class="st0">&quot;nt&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">// 11 (last occurrence of nt)</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">echo</span> <span class="kw3">strpos</span><span class="br0">&#40;</span><span class="re1">$string</span><span class="sy0">,</span> <span class="st0">&quot;nt&quot;</span><span class="sy0">,</span> <span class="nu0">4</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">// 11 (first occurrence of nt after 4-th position)</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">var_dump</span><span class="br0">&#40;</span><span class="kw3">strpos</span><span class="br0">&#40;</span><span class="re1">$string</span><span class="sy0">,</span> <span class="st0">&quot;count&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">// FALSE, because strpos() is case-sensitive</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">echo</span> stripos<span class="br0">&#40;</span><span class="re1">$string</span><span class="sy0">,</span> <span class="st0">&quot;Count&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">//0</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">?&gt;</span></div>
</li>
</ol>
</div>
<p>Be careful when you verify the result of those php functions! When the searched string is at the begining of the string in which we are searching, the strpos() function returns 0, which is == FALSE; so if we use the == operator there is the risk to get wrong conclusions:</p>
<div class="geshi no php">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">&lt;?php</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$string</span> <span class="sy0">=</span> <span class="st0">&quot;Count of Monte Cristo&quot;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">if</span><span class="br0">&#40;</span><span class="kw3">strpos</span><span class="br0">&#40;</span><span class="re1">$string</span><span class="sy0">,</span> <span class="st0">&quot;Co&quot;</span><span class="br0">&#41;</span> <span class="sy0">==</span> <span class="kw2">false</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> <span class="co1">// &quot;Co&quot; is at position 0, which == false!</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="kw3">echo</span> <span class="st0">&quot;It hasn&#39;t been found&quot;</span><span class="sy0">;</span> <span class="co1">// this line will execute!</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">?&gt;</span></div>
</li>
</ol>
</div>


<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.mysqlphptutorial.com/functions/strpos-find-the-position-of-a-string/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP sef url function</title>
		<link>http://www.mysqlphptutorial.com/functions/php-sef-url-function/</link>
		<comments>http://www.mysqlphptutorial.com/functions/php-sef-url-function/#comments</comments>
		<pubDate>Wed, 22 Jul 2009 11:48:24 +0000</pubDate>
		<dc:creator>PHP HELP</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Functions]]></category>
		<category><![CDATA[php functions]]></category>
		<category><![CDATA[sef]]></category>

		<guid isPermaLink="false">http://www.mysqlphptutorial.com/?p=81</guid>
		<description><![CDATA[This is another PHP sef function, much better to use in case you want to get remove characters that are not a-z, 0-9, dash, underscore or space, then remove all leading and trailing spaces, change all dashes, underscores and spaces to dashes and return the modified string in lower case. PHP search engine friendly url [...]


Related posts:<ol><li><a href='http://www.mysqlphptutorial.com/functions/php-sef-clean-url-function/' rel='bookmark' title='Permanent Link: PHP SEF Clean url function'>PHP SEF Clean url function</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>This is another PHP sef function, much better to use in case you want to get remove characters that are not a-z, 0-9, dash, underscore or space, then remove all leading and trailing spaces, change all dashes, underscores and spaces to dashes and return the modified string in lower case.<br />
<span id="more-81"></span></p>
<h2>PHP search engine friendly url function</h2>
<div class="geshi no php">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">function</span> sef<span class="br0">&#40;</span><span class="re1">$string</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// remove all characters that aren’t a-z, 0-9, dash, underscore or space</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$not_acceptable_characters</span> <span class="sy0">=</span> <span class="st0">&#39;#[^-a-zA-Z0-9_ ]#&#39;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$string</span> <span class="sy0">=</span> <span class="kw3">preg_replace</span><span class="br0">&#40;</span><span class="re1">$not_acceptable_characters</span><span class="sy0">,</span> <span class="st0">&#39;&#39;</span><span class="sy0">,</span> <span class="re1">$string</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// remove all leading and trailing spaces</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$string</span> <span class="sy0">=</span> <span class="kw3">trim</span><span class="br0">&#40;</span><span class="re1">$string</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// change all dashes, underscores and spaces to dashes</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$string</span> <span class="sy0">=</span> <span class="kw3">preg_replace</span><span class="br0">&#40;</span><span class="st0">&#39;#[-_ ]+#&#39;</span><span class="sy0">,</span> <span class="st0">&#39;-&#39;</span><span class="sy0">,</span> <span class="re1">$string</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// return the modified string</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">return</span> <span class="kw3">strtolower</span><span class="br0">&#40;</span><span class="re1">$string</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>


<p>Related posts:<ol><li><a href='http://www.mysqlphptutorial.com/functions/php-sef-clean-url-function/' rel='bookmark' title='Permanent Link: PHP SEF Clean url function'>PHP SEF Clean url function</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.mysqlphptutorial.com/functions/php-sef-url-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>php echo and print differences</title>
		<link>http://www.mysqlphptutorial.com/wiki/php-echo-and-print-differences/</link>
		<comments>http://www.mysqlphptutorial.com/wiki/php-echo-and-print-differences/#comments</comments>
		<pubDate>Wed, 27 May 2009 09:56:32 +0000</pubDate>
		<dc:creator>PHP HELP</dc:creator>
				<category><![CDATA[wiki]]></category>
		<category><![CDATA[php echo]]></category>
		<category><![CDATA[php print]]></category>

		<guid isPermaLink="false">http://www.mysqlphptutorial.com/?p=73</guid>
		<description><![CDATA[There are some differences between echo and print in php, echo and print are not functions. First, you can pass more than one parameter to echo, print doesn&#8217;t allow more than one parameter. Example: &#60;?php $a = 5; $b = 6; &#160; echo $a; // will output 5 echo $a, $6; // outputs 56 &#160; [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p>There are some differences between echo and print in php, echo and print are not functions.<br />
First, you can pass more than one parameter to echo, print doesn&#8217;t allow more than one parameter.<br />
Example:</p>
<div class="geshi no php">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">&lt;?php</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$a</span> <span class="sy0">=</span> <span class="nu0">5</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$b</span> <span class="sy0">=</span> <span class="nu0">6</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">echo</span> <span class="re1">$a</span><span class="sy0">;</span> <span class="co1">// will output 5</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">echo</span> <span class="re1">$a</span><span class="sy0">,</span> $<span class="nu0">6</span><span class="sy0">;</span> <span class="co1">// outputs 56</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">print</span> <span class="re1">$a</span><span class="sy0">;</span> <span class="co1">//will output 5</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">print</span> <span class="re1">$a</span><span class="sy0">,</span> <span class="re1">$b</span><span class="sy0">;</span> <span class="co1">// error, print doesn&#39;t allow more than one parameter</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">?&gt;</span></div>
</li>
</ol>
</div>
<p>Now, let&#8217;s see something interesting&#8230;</p>
<div class="geshi no php">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">&lt;?php</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$a</span> <span class="sy0">=</span> <span class="nu0">5</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">echo</span> <span class="st0">&quot; <span class="es0">\$</span>a is:&quot;</span> <span class="sy0">.</span> <span class="kw3">print</span> <span class="re1">$a</span><span class="sy0">;</span> <span class="co1">// will output 5 $a is 1</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">?&gt;</span></div>
</li>
</ol>
</div>
<p>First, you use \ (backslash) character to treat $a as a string not variable. Then, this is important, the code will be executed in this manner: first is executed <strong>print</strong> then <strong>echo</strong>. You may ask but why it will output &#8220;1&#8243;&#8230; Let&#8217;s see the next example:<br />
Remember that print($arg)  will return 1!</p>
<div class="geshi no php">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">&lt;?php</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$a</span> <span class="sy0">=</span> <span class="nu0">5</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">echo</span> <span class="br0">&#40;</span><span class="kw3">print</span><span class="br0">&#40;</span><span class="re1">$a</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">// will output 51</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">?&gt;</span></div>
</li>
</ol>
</div>
<p>As you can see, it will output 51 because php print is executed first (5) and with echo returns 1.</p>


<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.mysqlphptutorial.com/wiki/php-echo-and-print-differences/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
