<?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>Capable SEO &#187; php</title>
	<atom:link href="http://www.capableseo.com/tag/php/feed" rel="self" type="application/rss+xml" />
	<link>http://www.capableseo.com</link>
	<description></description>
	<lastBuildDate>Mon, 12 Apr 2010 08:42:43 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to do PHP While Loops</title>
		<link>http://www.capableseo.com/how-to-do-php-while-loops.html</link>
		<comments>http://www.capableseo.com/how-to-do-php-while-loops.html#comments</comments>
		<pubDate>Thu, 30 Jul 2009 14:02:02 +0000</pubDate>
		<dc:creator></dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[basics]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.capableseo.com/?p=104</guid>
		<description><![CDATA[Now that you know how to use if then statements lets move on to a basic loop.

Lets get started by opening your favorite editor and starting a fresh source page. Start off with the basic coding which denotes a php area. &#60;?php ?&#62;
Now lets add in a variable and an echo statement. Give one variable [...]]]></description>
			<content:encoded><![CDATA[<p>Now that you know how to use if then statements lets move on to a basic loop.</p>
<ol>
<li>Lets get started by opening your favorite editor and starting a fresh source page. Start off with the basic coding which denotes a php area. <span>&lt;?php ?&gt;</span></li>
<li>Now lets add in a variable and an echo statement. Give one variable a value of 0 then echo it.<br />
<table border="0" cellspacing="0" cellpadding="0" width="350" bgcolor="#cccccc">
<tbody>
<tr>
<td><code><span style="color: #000000;"> <span style="color: #0000bb;">&lt;?php<br />
$x</span><span style="color: #007700;">=</span><span style="color: #0000bb;">0</span><span style="color: #007700;">;<br />
echo </span><span style="color: #0000bb;">$x</span><span style="color: #007700;">;<br />
</span><span style="color: #0000bb;">?&gt;<br />
</span> </span> </code></td>
</tr>
</tbody>
</table>
<p>This should print out <span>0</span>.</p>
<p>PHP generally starts many constructs at 0, not at 1 so its generally better to start counting from 0 in programming..</li>
<li>Now lets add in a basic loop. The while statement is very similar to an if statement except a while loop will do the things as long as its conditions are met (or until timeout which is generally 3-5 minutes depending on your server settings).<br />
<table border="0" cellspacing="0" cellpadding="0" width="350" bgcolor="#cccccc">
<tbody>
<tr>
<td><code><span style="color: #000000;"> <span style="color: #0000bb;">&lt;?php<br />
</span><span style="color: #007700;">while (</span><span style="color: #ff8000;">/*requirements*/</span><span style="color: #007700;">)<br />
{<br />
</span><span style="color: #ff8000;">//Stuff to do<br />
</span><span style="color: #007700;">}<br />
</span><span style="color: #0000bb;">?&gt;<br />
</span> </span> </code></td>
</tr>
</tbody>
</table>
<p>This won&#8217;t print anything yet</li>
<li>Now lets make that actually do something. We&#8217;ll have it run 5 times, so while <span>$x</span>&lt;5 do something. Of course we have to increase <span>$x</span> inside the loop otherwise it won&#8217;t end. So the only action we have right now is adding one to <span>$x</span>, we can do this with <span>$x=$x+1;</span> or in english x is equal to x +1.<br />
<table border="0" cellspacing="0" cellpadding="0" width="350" bgcolor="#cccccc">
<tbody>
<tr>
<td><code><span style="color: #000000;"> <span style="color: #0000bb;">&lt;?php<br />
$x</span><span style="color: #007700;">=</span><span style="color: #0000bb;">0</span><span style="color: #007700;">;<br />
while (</span><span style="color: #0000bb;">$x</span><span style="color: #007700;">&lt;</span><span style="color: #0000bb;">5</span><span style="color: #007700;">)<br />
{<br />
</span><span style="color: #0000bb;">$x</span><span style="color: #007700;">=</span><span style="color: #0000bb;">$x</span><span style="color: #007700;">+</span><span style="color: #0000bb;">1</span><span style="color: #007700;">;<br />
}<br />
</span><span style="color: #0000bb;">?&gt;<br />
</span> </span> </code></td>
</tr>
</tbody>
</table>
<p>This won&#8217;t print anything yet</li>
<li>Now lets add on an echo so we can see the progress of <span>$x</span> counting up towards 5.<br />
<table border="0" cellspacing="0" cellpadding="0" width="350" bgcolor="#cccccc">
<tbody>
<tr>
<td><code><span style="color: #000000;"> <span style="color: #0000bb;">&lt;?php<br />
$x</span><span style="color: #007700;">=</span><span style="color: #0000bb;">0</span><span style="color: #007700;">;<br />
while (</span><span style="color: #0000bb;">$x</span><span style="color: #007700;">&lt;</span><span style="color: #0000bb;">5</span><span style="color: #007700;">)<br />
{<br />
echo </span><span style="color: #0000bb;">$x</span><span style="color: #007700;">;<br />
</span><span style="color: #0000bb;">$x</span><span style="color: #007700;">=</span><span style="color: #0000bb;">$x</span><span style="color: #007700;">+</span><span style="color: #0000bb;">1</span><span style="color: #007700;">;<br />
}<br />
</span><span style="color: #0000bb;">?&gt;<br />
</span> </span> </code></td>
</tr>
</tbody>
</table>
<p>This should print out &#8220;<span>12345</span>&#8220;</li>
<li>Ok now there is a better way to add one to <span>$x</span> and thats a special operation which is coded like this <span>++$x;</span></li>
<li>Now lets add some text to each echo so it looks a bit nicer. You can print a variable and letters by using an echo with quotes. so in this statement <span>echo &#8220;x: $x&#8221;;</span> the first x will simply be the letter x and the second one which is preceded by a $ will be the variable.<br />
<table border="0" cellspacing="0" cellpadding="0" width="350" bgcolor="#cccccc">
<tbody>
<tr>
<td><code><span style="color: #000000;"> <span style="color: #0000bb;">&lt;?php<br />
$x</span><span style="color: #007700;">=</span><span style="color: #0000bb;">0</span><span style="color: #007700;">;<br />
while (</span><span style="color: #0000bb;">$x</span><span style="color: #007700;">&lt;</span><span style="color: #0000bb;">5</span><span style="color: #007700;">)<br />
{<br />
echo </span><span style="color: #dd0000;">"x=$x"</span><span style="color: #007700;">;<br />
++</span><span style="color: #0000bb;">$x</span><span style="color: #007700;">;<br />
}<br />
</span><span style="color: #0000bb;">?&gt;<br />
</span> </span> </code></td>
</tr>
</tbody>
</table>
<p>This should print out &#8220;<span>x: 1x: 2x: 3x: 4x: 5</span>&#8221;<br />
Now this doesn&#8217;t look much nicer (actually it looks worse!), but we&#8217;ll fix that in the next step.</li>
<li>A PHP echo will place code directly into the html of a file. So if you type html code into the echo you can use different html functions to change displays. In this way you can make things bold, manipulate css styles etc. For now we&#8217;ll just add a <span>&lt;br&gt;</span> to the end of each line this will make the numbers go to different lines.<br />
<table border="0" cellspacing="0" cellpadding="0" width="350" bgcolor="#cccccc">
<tbody>
<tr>
<td><code><span style="color: #000000;"> <span style="color: #0000bb;">&lt;?php<br />
$x</span><span style="color: #007700;">=</span><span style="color: #0000bb;">0</span><span style="color: #007700;">;<br />
while (</span><span style="color: #0000bb;">$x</span><span style="color: #007700;">&lt;</span><span style="color: #0000bb;">5</span><span style="color: #007700;">)<br />
{<br />
echo </span><span style="color: #dd0000;">"x=$x&lt;br&gt;"</span><span style="color: #007700;">;<br />
++</span><span style="color: #0000bb;">$x</span><span style="color: #007700;">;<br />
}<br />
</span><span style="color: #0000bb;">?&gt;<br />
</span> </span> </code></td>
</tr>
</tbody>
</table>
<p>This should print out:<br />
<span>x: 1<br />
x: 2<br />
x: 3<br />
x: 4<br />
x: 5</span></li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.capableseo.com/how-to-do-php-while-loops.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>If Then Math PHP Statements</title>
		<link>http://www.capableseo.com/if-then-math-php-statements.html</link>
		<comments>http://www.capableseo.com/if-then-math-php-statements.html#comments</comments>
		<pubDate>Wed, 15 Jul 2009 04:43:02 +0000</pubDate>
		<dc:creator></dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.capableseo.com/?p=49</guid>
		<description><![CDATA[
Lets get started by opening your favorite editor and starting a fresh source page. Start off with the basic coding which denotes a php area. &#60;?php ?&#62;
Now lets add in some basic variables and an echo statement. Give two variables a value of 2, and a third variable a value equal to the previous to [...]]]></description>
			<content:encoded><![CDATA[<ol>
<li>Lets get started by opening your favorite editor and starting a fresh source page. Start off with the basic coding which denotes a php area. <span>&lt;?php ?&gt;</span></li>
<li>Now lets add in some basic variables and an echo statement. Give two variables a value of 2, and a third variable a value equal to the previous to variables added together.<br />
<table border="0" cellspacing="0" cellpadding="0" width="350" bgcolor="#cccccc">
<tbody>
<tr>
<td><code><span style="color: #000000;"> <span style="color: #0000bb;">&lt;?php<br />
$x</span><span style="color: #007700;">=</span><span style="color: #0000bb;">2</span><span style="color: #007700;">;<br />
</span><span style="color: #0000bb;">$y</span><span style="color: #007700;">=</span><span style="color: #0000bb;">2</span><span style="color: #007700;">;<br />
</span><span style="color: #0000bb;">$number</span><span style="color: #007700;">=</span><span style="color: #0000bb;">$x</span><span style="color: #007700;">+</span><span style="color: #0000bb;">$y</span><span style="color: #007700;">;<br />
echo </span><span style="color: #0000bb;">$number</span><span style="color: #007700;">;<br />
</span><span style="color: #0000bb;">?&gt;<br />
</span> </span> </code></td>
</tr>
</tbody>
</table>
<p>This should print out <span>4</span> .</li>
<li>Try changing the <span>+</span> to different mathmatical operators these are:<br />
<span>/</span> Divide<br />
<span>*</span> Multiply<br />
<span>-</span> Subtract</li>
<li>Now we&#8217;re going to add in an if then statement. Basically if statements are logical, if certain requirements are met then do something. An if then statement looks like this<br />
<table border="0" cellspacing="0" cellpadding="0" width="350" bgcolor="#cccccc">
<tbody>
<tr>
<td><code><span style="color: #000000;"> <span style="color: #0000bb;">&lt;?php<br />
</span><span style="color: #007700;">if (</span><span style="color: #ff8000;">/*requirements*/</span><span style="color: #007700;">)<br />
{<br />
</span><span style="color: #ff8000;">//Stuff to do<br />
</span><span style="color: #007700;">}<br />
</span><span style="color: #0000bb;">?&gt;<br />
</span> </span> </code></td>
</tr>
</tbody>
</table>
<p>The if statement is one of the few that doesn&#8217;t require a <span>;</span> after it.</li>
<li>Now lets a simple statement that says, &#8216;if&#8217; <span>&#8216;$number</span> is not equal to four&#8217; &#8216;echo Thats not Four&#8217;. This code looks like this.<br />
<table border="0" cellspacing="0" cellpadding="0" width="350" bgcolor="#cccccc">
<tbody>
<tr>
<td><code><span style="color: #000000;"> <span style="color: #0000bb;">&lt;?php<br />
$x</span><span style="color: #007700;">=</span><span style="color: #0000bb;">1</span><span style="color: #007700;">;<br />
</span><span style="color: #0000bb;">$y</span><span style="color: #007700;">=</span><span style="color: #0000bb;">2</span><span style="color: #007700;">;<br />
</span><span style="color: #0000bb;">$number</span><span style="color: #007700;">=</span><span style="color: #0000bb;">$x</span><span style="color: #007700;">+</span><span style="color: #0000bb;">$y</span><span style="color: #007700;">;</p>
<p>if (</span><span style="color: #0000bb;">$number</span><span style="color: #007700;">!=</span><span style="color: #0000bb;">4</span><span style="color: #007700;">)<br />
{<br />
echo </span><span style="color: #dd0000;">"Thats not Four"</span><span style="color: #007700;">;<br />
}<br />
</span><span style="color: #0000bb;">?&gt;<br />
</span> </span> </code></td>
</tr>
</tbody>
</table>
<p>This should print out &#8220;<span>Thats not Four</span>&#8221;</p>
<p>The comparison operators in PHP are as follows:<br />
<span>!=</span> Is not equal to<br />
<span>==</span> Equal to<br />
<span>&gt;</span> Greater than<br />
<span>&lt;</span> Less than<br />
<span>&gt;=</span> Greater than or Equal to<br />
<span>&lt;=</span> Greater than or Equal to</li>
<li>Now lets say you want to check if the number is between 5 and 10. You&#8217;ll need to use two checks in the if instead of one. So you need to say &#8216;if&#8217; <span>&#8216;$number</span> is greater than or equal to 5 and less than or equal to 10&#8242; &#8216;echo number is between 5 and 10&#8242;. The code for this looks like this:<br />
<table border="0" cellspacing="0" cellpadding="0" width="350" bgcolor="#cccccc">
<tbody>
<tr>
<td><code><span style="color: #000000;"> <span style="color: #0000bb;">&lt;?php<br />
$x</span><span style="color: #007700;">=</span><span style="color: #0000bb;">1</span><span style="color: #007700;">;<br />
</span><span style="color: #0000bb;">$y</span><span style="color: #007700;">=</span><span style="color: #0000bb;">2</span><span style="color: #007700;">;<br />
</span><span style="color: #0000bb;">$number</span><span style="color: #007700;">=</span><span style="color: #0000bb;">$x</span><span style="color: #007700;">+</span><span style="color: #0000bb;">$y</span><span style="color: #007700;">;</p>
<p>if (</span><span style="color: #0000bb;">$number</span><span style="color: #007700;">&gt;=</span><span style="color: #0000bb;">5 </span><span style="color: #007700;">&amp;&amp; </span><span style="color: #0000bb;">$number</span><span style="color: #007700;">&lt;=</span><span style="color: #0000bb;">10</span><span style="color: #007700;">)<br />
{<br />
echo </span><span style="color: #dd0000;">"number is between 5 and 10"</span><span style="color: #007700;">;<br />
}<br />
</span><span style="color: #0000bb;">?&gt;<br />
</span> </span> </code></td>
</tr>
</tbody>
</table>
<p>This shouldn&#8217;t print anything</p>
<p>Logical Operators for PHP<br />
<span>&amp;&amp;</span> and<br />
<span>||</span> or</li>
<li>Now this is fine and all except what, happens when your number doesn&#8217;t fit the criteria? Nothing happens. So lets add on the final part of an If Then statement. So now PHP will go if <span>$number</span> is between 5-10 do this, or else do this. The code looks like this:<br />
<table border="0" cellspacing="0" cellpadding="0" width="350" bgcolor="#cccccc">
<tbody>
<tr>
<td><code><span style="color: #000000;"> <span style="color: #0000bb;">&lt;?php<br />
$x</span><span style="color: #007700;">=</span><span style="color: #0000bb;">1</span><span style="color: #007700;">;<br />
</span><span style="color: #0000bb;">$y</span><span style="color: #007700;">=</span><span style="color: #0000bb;">2</span><span style="color: #007700;">;<br />
</span><span style="color: #0000bb;">$number</span><span style="color: #007700;">=</span><span style="color: #0000bb;">$x</span><span style="color: #007700;">+</span><span style="color: #0000bb;">$y</span><span style="color: #007700;">;</p>
<p>if (</span><span style="color: #0000bb;">$number</span><span style="color: #007700;">&gt;=</span><span style="color: #0000bb;">5 </span><span style="color: #007700;">&amp;&amp; </span><span style="color: #0000bb;">$number</span><span style="color: #007700;">&lt;=</span><span style="color: #0000bb;">10</span><span style="color: #007700;">)<br />
{<br />
echo </span><span style="color: #dd0000;">"number is between 5 and 10"</span><span style="color: #007700;">;<br />
}<br />
else<br />
{<br />
echo </span><span style="color: #dd0000;">"number is less then 5 or greater than 10"</span><span style="color: #007700;">;<br />
}<br />
</span><span style="color: #0000bb;">?&gt;<br />
</span> </span> </code></td>
</tr>
</tbody>
</table>
<p>This should print <span>number is less then 5 or greater than 10</span></li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.capableseo.com/if-then-math-php-statements.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
