<?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>Simply Dhavest - Filipino PHP Programmer &#187; PHP Tutorials</title>
	<atom:link href="http://www.dhavest.com/category/phptutorial/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dhavest.com</link>
	<description>Journal of a Filipino Programmer</description>
	<lastBuildDate>Fri, 29 Jan 2010 14:23:47 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Convert array to string</title>
		<link>http://www.dhavest.com/2007/10/19/convert-array-to-string/</link>
		<comments>http://www.dhavest.com/2007/10/19/convert-array-to-string/#comments</comments>
		<pubDate>Fri, 19 Oct 2007 07:21:20 +0000</pubDate>
		<dc:creator>conai</dc:creator>
				<category><![CDATA[Arrays]]></category>
		<category><![CDATA[Strings]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[implode]]></category>
		<category><![CDATA[php tutorial]]></category>
		<category><![CDATA[string]]></category>

		<guid isPermaLink="false">http://www.dhavest.com/2007/10/19/convert-array-to-string/</guid>
		<description><![CDATA[Problem: You want to convert an array to string so that it is easier to print the result instead of looping inside the array and have this printed
Old Solution:
$aArr = array("Have you ever seen",
"the beauty of the world.",
"The wonderful creation of the Lord." );
foreach($aArr as $sString) {
    print $sString;
}
Other Solution:
$aArr = array("Have [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Problem:</strong> You want to convert an array to string so that it is easier to print the result instead of looping inside the array and have this printed</p>
<p><strong>Old Solution:</strong></p>
<pre>$aArr = array("Have you ever seen",</pre>
<pre>"the beauty of the world.",</pre>
<pre>"The wonderful creation of the Lord." );</pre>
<pre>foreach($aArr as $sString) {</pre>
<pre>    print $sString;</pre>
<pre>}</pre>
<p><strong>Other Solution:</strong></p>
<pre>$aArr = array("Have you ever seen",</pre>
<pre>"the beauty of the world.",</pre>
<pre>"The wonderful creation of the Lord." );</pre>
<pre>$sString = implode(" ", $aArr);</pre>
<pre>print $sString;</pre>
<p><strong>In Action:</strong> I want to execute a linux command via PHP and get its result and extract the desire content. The example below will try to extract the ip address from the ifconfig command</p>
<pre>exec("ifconfig", $aOutput);</pre>
<pre>$sTempString = implode(" ", $aOutput);</pre>
<pre>preg_match("/inet\saddr:(.*?)\s/i", $sTempString, $aMatch);</pre>
<pre>print $aMatch[1]; //</pre>
<p><!--adsense--></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dhavest.com/2007/10/19/convert-array-to-string/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Determining if a number is odd or even</title>
		<link>http://www.dhavest.com/2007/10/18/determining-if-a-number-is-odd-or-even/</link>
		<comments>http://www.dhavest.com/2007/10/18/determining-if-a-number-is-odd-or-even/#comments</comments>
		<pubDate>Thu, 18 Oct 2007 16:31:38 +0000</pubDate>
		<dc:creator>conai</dc:creator>
				<category><![CDATA[Operators]]></category>

		<guid isPermaLink="false">http://www.dhavest.com/2007/10/18/determining-if-a-number-is-odd-or-even/</guid>
		<description><![CDATA[Problem: We wanted to determine if a number is even or odd
Notes: We know that even number end with 0, 2, 4, 6, 8 and odd numbers ends with 1, 3, 5, 7, 9. So how will we know if a number given is an even or odd number in a program..
Solution:
&#60;?
$magic_number = 123568;
if($magic_number % [...]]]></description>
			<content:encoded><![CDATA[<p>Problem: We wanted to determine if a number is even or odd</p>
<p>Notes: We know that even number end with 0, 2, 4, 6, 8 and odd numbers ends with 1, 3, 5, 7, 9. So how will we know if a number given is an even or odd number in a program..</p>
<p>Solution:</p>
<pre>&lt;?</pre>
<pre>$magic_number = 123568;</pre>
<pre>if($magic_number % 2 == 0) {</pre>
<pre>    print "The number is even.";</pre>
<pre>}  else {</pre>
<pre>    print "The number is odd.";</pre>
<pre>}</pre>
<pre>?&gt;</pre>
<p>Explanation: In the program above we use the modulus division. Modulus division unlike the ordinary division (/) returns the remainder instead of the quotient. So we tried modulo dividing the given number by 2 to determine if it is divisible by 2.</p>
<p><!--adsense--></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dhavest.com/2007/10/18/determining-if-a-number-is-odd-or-even/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Swapping variables without using temporary variable</title>
		<link>http://www.dhavest.com/2007/10/11/swapping-variables-without-using-temporary-variable/</link>
		<comments>http://www.dhavest.com/2007/10/11/swapping-variables-without-using-temporary-variable/#comments</comments>
		<pubDate>Thu, 11 Oct 2007 11:59:25 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Variables]]></category>

		<guid isPermaLink="false">http://www.dhavest.com/2007/10/11/swapping-variables-without-using-temporary-variable/</guid>
		<description><![CDATA[For example we wanted to swap two variable values given
$x = 10;
$y = 20;
The usual way of exchanging their variables is to use a temporary variable like the one below
$x = 10;
$y = 20;
$z = $x; // $z will be equal to 10 now which will serve as a temporary variable
$x = y; // $x [...]]]></description>
			<content:encoded><![CDATA[<p>For example we wanted to swap two variable values given</p>
<pre><font color="#008000">$x = 10;</font></pre>
<pre><font color="#008000">$y = 20;</font></pre>
<p>The usual way of exchanging their variables is to use a temporary variable like the one below</p>
<pre><font color="#008000">$x = 10;</font></pre>
<pre><font color="#008000">$y = 20;</font></pre>
<pre><font color="#008000">$z = $x; // $z will be equal to 10 now which will serve as a temporary variable</font></pre>
<pre><font color="#008000">$x = y; // $x will be equal to 20 now
</font></pre>
<pre><font color="#008000">$y = $z; // $y will be 10 now</font></pre>
<p>Their is another way to do this without using temporary variable is the use of list() function</p>
<pre><font color="#008000">$x = 10;</font></pre>
<pre><font color="#008000">$y = 20; </font></pre>
<pre><font color="#008000">list($x, $y) = array($y, $x);</font></pre>
<p>You can also do this in multiple variables</p>
<pre><font color="#008000">$sDog1 = "Boston Terrier";</font></pre>
<pre><font color="#008000">$sDog2 = "American Bulldog";</font></pre>
<pre><font color="#008000">$sDog3 = "German Shepperd";</font></pre>
<pre><font color="#008000">$sDog4 = "Great Dane";</font></pre>
<pre><font color="#008000">list($sDog1, $sDog2, $sDog3, $sDog4) = array($sDog3, $sDog1, $sDog4, $sDog2); </font></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.dhavest.com/2007/10/11/swapping-variables-without-using-temporary-variable/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting a single character in a string</title>
		<link>http://www.dhavest.com/2007/10/09/getting-a-single-character-in-a-string/</link>
		<comments>http://www.dhavest.com/2007/10/09/getting-a-single-character-in-a-string/#comments</comments>
		<pubDate>Tue, 09 Oct 2007 04:44:44 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Strings]]></category>

		<guid isPermaLink="false">http://www.dhavest.com/2007/10/09/getting-a-single-character-in-a-string/</guid>
		<description><![CDATA[This snippet of code will show how to get individual character from a string in a variable
$sMyName = &#8220;Darwin&#8221;;
print $sMyName[1]; // will print the letter &#8220;a&#8221;
]]></description>
			<content:encoded><![CDATA[<p>This snippet of code will show how to get individual character from a string in a variable</p>
<p>$sMyName = &#8220;Darwin&#8221;;</p>
<p>print $sMyName[1]; // will print the letter &#8220;a&#8221;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dhavest.com/2007/10/09/getting-a-single-character-in-a-string/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to use heredoc in PHP</title>
		<link>http://www.dhavest.com/2007/10/09/how-to-use-heredoc-in-php/</link>
		<comments>http://www.dhavest.com/2007/10/09/how-to-use-heredoc-in-php/#comments</comments>
		<pubDate>Tue, 09 Oct 2007 04:13:17 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Strings]]></category>

		<guid isPermaLink="false">http://www.dhavest.com/2007/10/09/how-to-use-heredoc-in-php/</guid>
		<description><![CDATA[Heredoc also known as here-document is a way of specifying string literals or printing them literally without the use of quotes to threat them as literal strings. Heredoc preserves the line breaks and other whitespace (including indentation) in the text.
Heredocs start with &#60;&#60;&#60; and a token or also known as delimiting identifier. The token or [...]]]></description>
			<content:encoded><![CDATA[<p>Heredoc also known as here-document is a way of specifying string literals or printing them literally without the use of quotes to threat them as literal strings. Heredoc preserves the line breaks and other whitespace (including indentation) in the text.</p>
<p>Heredocs start with <tt>&lt;&lt;&lt;</tt> and a token or also known as delimiting identifier. The token or delimiting identifier  don&#8217;t leading or trailing whitespace and followed by semicolon a to end the statement.</p>
<p>Example: We wanted to print this string</p>
<pre><font color="#008000">The quick brown fox</font></pre>
<pre><font color="#008000">jumps over the lazy dog.</font></pre>
<pre><font color="#008000">But what is the name of that dog </font></pre>
<pre><font color="#008000">whom the fox jumped over.</font></pre>
<p>Usually we will use the print built in function of php and put line breaks to separate the lines</p>
<pre><font color="#008000">print "The quick brown fox \n";</font></pre>
<pre><font color="#008000">print "jumps over the lazy dog. \n";</font></pre>
<pre><font color="#008000">print "But what is the name of that dog \n"; </font></pre>
<pre><font color="#008000">print "whom the fox jumped over \n";</font></pre>
<p>In heredoc we literally print these sequence string without having to print all the lines 1 by 1;</p>
<p>Using heredoc</p>
<pre><font color="#008000">print &lt;&lt;&lt; DOGS
</font></pre>
<pre><font color="#008000">The quick brown fox</font></pre>
<pre><font color="#008000">jumps over the lazy dog.</font></pre>
<pre><font color="#008000">But what is the name of that dog </font></pre>
<pre><font color="#008000">whom the fox jumped over.</font></pre>
<pre><font color="#008000">DOGS; </font></pre>
<p><strong>Heredocs in HTML</strong></p>
<pre><font color="#008000">$sAnimal = "cat";</font></pre>
<pre><font color="#008000">$aZoo = array("elephant","zebra","monkey","lion","bear");</font></pre>
<pre><font color="#008000">print &lt;&lt;&lt; ZOO</font></pre>
<pre><font color="#008000">There are different animals in the zoo.</font></pre>
<pre><font color="#008000">It includes &lt;b&gt;$aZoo[1], $aZoo[3].&lt;/b&gt;</font></pre>
<pre><font color="#008000">There are also &lt;font color="red"&gt;$sAnimal&lt;/font&gt; here.</font></pre>
<pre><font color="#008000">ZOO;</font></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.dhavest.com/2007/10/09/how-to-use-heredoc-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My PHP Coding Standard</title>
		<link>http://www.dhavest.com/2007/10/07/my-php-coding-standard/</link>
		<comments>http://www.dhavest.com/2007/10/07/my-php-coding-standard/#comments</comments>
		<pubDate>Sun, 07 Oct 2007 11:49:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP Tutorials]]></category>

		<guid isPermaLink="false">http://www.dhavest.com/2007/10/07/my-php-coding-standard/</guid>
		<description><![CDATA[Before I start writing my own PHP tutorials, I would to set the coding standards I will be following in the course of this tutorial. This aims to standardize all my snippets ( small chunk of code) in all examples I will be giving. I would like to emphasize that this is not a standard [...]]]></description>
			<content:encoded><![CDATA[<p>Before I start writing my own PHP tutorials, I would to set the coding standards I will be following in the course of this tutorial. This aims to standardize all my snippets ( small chunk of code) in all examples I will be giving. I would like to emphasize that this is not a standard to all PHP programmers but just my personal preferences which we all do have.</p>
<p><strong>Comments &#8211; </strong>- comments are piece of information that programmers usually put to their code to explain what it does. Comments are not actually part of the execution of a program but instead they are ignored by the PHP interpreter. It is a good practice in a programmer to put comments on his code because in the future, comments are the only guide a programmer can follow to understand a big pile of code. Comments may vary depending on what type comment to put.</p>
<p><!--adsense#horizontal--></p>
<p>1. single line comments &#8211; for single line commenting I use the double forward slash //</p>
<p><em>Example:</em></p>
<pre>// this line will print your name</pre>
<pre>print "My name is Juan dela Cruz";</pre>
<p>2. multi-line comment &#8211; for multi line I use /* and the closing */</p>
<p><em>Example:</em></p>
<pre>/*</pre>
<pre>This is a multi-line comment</pre>
<pre>and goes all the way</pre>
<pre>up to this point</pre>
<pre>*/</pre>
<p><strong>Variables</strong></p>
<p>for variables I use the camelize form. Meaning letters in my variable have combination of upper and lower case. But in addition I am affixing a single letter prefix that will determine the datatype of that variable. For example, if I would declare an array variable I would write $aMyArray.</p>
<p><em>Example:</em></p>
<pre>$aMyArray = array(1,2,3,4); // contains array values</pre>
<pre>$sYourName = "Conai"; // contains string values</pre>
<pre>$iLoop = 100; // contains integer values</pre>
<pre>$oDBConnection = mysql_connect("localhost", "username", "password"); // object</pre>
<pre>$bIsTrue = false;  // boolean</pre>
<pre>$mMixedVariable = "test"; // mixed variable, a variable that may vary in datatype</pre>
<pre></pre>
<p>For single usage or single letter variable there is  an exemption on my rule.</p>
<pre>for ($x=1; $x&lt;count($aMyArray); $x++) {</pre>
<pre>    &lt;statement here&gt;</pre>
<pre>}</pre>
<p>in the above example $x dont have any prefix on what datatype it is. I have sited this as my exemption.</p>
<pre></pre>
<pre></pre>
<p><strong>Constants</strong></p>
<p>as a rule constants should all be in uppercase and words separated by underscore(_)</p>
<p><em>Example:</em></p>
<pre>define('HOST',  'localhost');</pre>
<pre>define('USER_NAME', 'root');</pre>
<pre>define('PASSWORD', '1234567a');</pre>
<pre></pre>
<pre></pre>
<pre></pre>
<p><strong>Conditional Statements</strong></p>
<p>if statement</p>
<pre>if ($x == 1) {</pre>
<pre>    &lt;statement here after 4 solid spaces&gt;</pre>
<pre>}</pre>
<p>if &#8211; else statement</p>
<pre>if ($x == null || $y != false) {</pre>
<pre>    &lt;statement of if after 4 solid spaces&gt;</pre>
<pre>} else {</pre>
<pre>    &lt;statement of else after 4 solid spaces&gt;</pre>
<pre>}</pre>
<p>if -else if &#8211; else</p>
<pre>if ($x &gt; count($aResults)) {</pre>
<pre>    &lt;statement of if after 4 solid spaces&gt;</pre>
<pre>} else if ($x &lt; count($aResults)) {</pre>
<pre>    &lt;statement of else fif after 4 solid spaces&gt;</pre>
<pre>} else {</pre>
<pre>    &lt;statement of else after 4 solid spaces&gt;</pre>
<pre>}</pre>
<pre></pre>
<p><strong>Loop statement</strong></p>
<p>for loop</p>
<pre>for($iCounter=0; $iCounter&lt;10; $iCounter++) {</pre>
<pre>    &lt;statement of for loop after 4 solid spaces&gt;</pre>
<pre>}</pre>
<pre></pre>
<p>while</p>
<pre>while( !feof($oHandle) ) {</pre>
<pre>    &lt;statement of while loop after 4 solid spaces&gt;</pre>
<pre>}</pre>
<p>do-while</p>
<pre>do {</pre>
<pre>    &lt;statement after 4 solid spaces&gt;</pre>
<pre>
}  while( $iLoop &gt; 10) ;</pre>
<pre></pre>
<pre></pre>
<p><strong>Functions </strong>- function names are the same as the camelize form of my variables. Function names usually starts with small letters.</p>
<p><em>Example: </em></p>
<pre>function checkThisVariable($mVariable) {</pre>
<pre>     if( is_integer($mVariable) ) {</pre>
<pre>        return "integer";
    } else if ( is_array($mVariable) ) {</pre>
<pre>        return "array";</pre>
<pre>    } else {</pre>
<pre>         return "undetermine";</pre>
<pre>    }</pre>
<pre>}</pre>
<pre></pre>
<p><strong>Class </strong>- class name are also in camelize form but the first letter is Capitalize to signify that it is a class when placed among other variables.</p>
<p><em>Example: </em></p>
<pre>class Cabinet {</pre>
<pre>    var $sDrawer;</pre>
<pre>    function Cabinet () {</pre>
<pre>        $this-&gt;sDrawer = true;</pre>
<pre>    }
}</pre>
<pre></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.dhavest.com/2007/10/07/my-php-coding-standard/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
