<?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"
	>

<channel>
	<title>Wowebmaster.com</title>
	<atom:link href="http://www.wowebmaster.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.wowebmaster.com</link>
	<description>World of Webmaster: Sharing Experiences</description>
	<pubDate>Wed, 03 Dec 2008 08:49:52 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5</generator>
	<language>en</language>
			<item>
		<title>Testing Your Design in IE6 &#038; IE7</title>
		<link>http://www.wowebmaster.com/css/2008/testing-your-design-in-ie6-ie7/</link>
		<comments>http://www.wowebmaster.com/css/2008/testing-your-design-in-ie6-ie7/#comments</comments>
		<pubDate>Wed, 03 Dec 2008 08:45:30 +0000</pubDate>
		<dc:creator>sguler</dc:creator>
		
		<category><![CDATA[Css]]></category>

		<category><![CDATA[Design]]></category>

		<guid isPermaLink="false">http://www.wowebmaster.com/?p=26</guid>
		<description><![CDATA[Work-around: Install IE6 and IE7 at Same Computer, Side by Side!]]></description>
			<content:encoded><![CDATA[<p>If you are a designer, then you know how it is complicated to code sites with cross-browser support. IE6 hacks,  Safari support, CSS resets and so on&#8230; You keep trying to balance your website across all browsers. Half of pain is because of installing and testing all of the browsers at the same time. However you also know that you can&#8217;t install internet explorer 6 and internet explorer 7 at the same time to your computer.</p>
<p><strong>Installing IE6 and IE7 Side by Side</strong></p>
<p>With a few googles, i found out  that you can actually install IE6 and IE7 in one computer. A few hacks to windows registry database, and a few file additions and deletions. Don&#8217;t be afraid, because someone has simplified it. Tredosoft is offering a software that supports Multiple IEs in one computer . Just download and run the file at <a title="Multiple IE Installation" href="http://tredosoft.com/Multiple_IE" target="_blank" style="color:#ff0000">this page</a> and start testing your web designs in multiple internet explorer versions ( IE5, IE6 and IE7). Enjoy.</p>
<p><a href="http://tredosoft.com/Multiple_IE" target="_blank"><img class="alignnone size-full wp-image-27" title="setup1" src="http://www.wowebmaster.com/wp-content/uploads/2008/12/setup1.png" alt="" width="406" height="317"  border="0"/></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.wowebmaster.com/css/2008/testing-your-design-in-ie6-ie7/feed/</wfw:commentRss>
		</item>
		<item>
		<title>IE6 Negative Margin Problem</title>
		<link>http://www.wowebmaster.com/css/2008/ie6-negative-margin-problem/</link>
		<comments>http://www.wowebmaster.com/css/2008/ie6-negative-margin-problem/#comments</comments>
		<pubDate>Tue, 02 Dec 2008 07:46:06 +0000</pubDate>
		<dc:creator>sguler</dc:creator>
		
		<category><![CDATA[Css]]></category>

		<guid isPermaLink="false">http://www.wowebmaster.com/?p=25</guid>
		<description><![CDATA[Work Around: Negative Margins in IE6]]></description>
			<content:encoded><![CDATA[<p>Designers should have faced with the problem of creating cross-browser designs. We have to serve to all of the visitors. Some may use Mozilla, some Internet Explorer 6 or IE7.</p>
<p>Usually, problem is related to IE6&#8217;s rendering engine.  One of the most common problem with IE6 is that it doesn&#8217;t render the negative margins as IE7 and Mozilla does. Negative margins is rendered hidden out of the layer in IE6.  Setting overflow to visible does not work and you go crazy.</p>
<p>The work around, making the negative margins visible, is so simple, it is even one of the simplest work arounds of the problems in IE6. Just add <em>position:relative</em> to your element with negative margins. This is it. Enjoy.</p>
<blockquote><p>position:relative</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.wowebmaster.com/css/2008/ie6-negative-margin-problem/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Simple Rounded Corners with Javascript</title>
		<link>http://www.wowebmaster.com/javascript/2008/simple-rounded-corners-with-javascript/</link>
		<comments>http://www.wowebmaster.com/javascript/2008/simple-rounded-corners-with-javascript/#comments</comments>
		<pubDate>Wed, 19 Nov 2008 22:12:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.wowebmaster.com/?p=23</guid>
		<description><![CDATA[Rounded Image Corners with Javascript. No more CSS headaches!]]></description>
			<content:encoded><![CDATA[<p>Everyone knows it is so painful to handle rounded corners with extra divs, slices making alignments harder than ever, using CSS. Now I introduce, no not me actually, <a title="Introducing Corners.js" href="http://corner.netzgesta.de" target="_blank">Christian Effenberger</a> , a way to do rounded corner effect on images with javascript. It is really easy and fun, so i won&#8217;t go on talking, rather, I&#8217;m going to explain how to use it.</p>
<p>Visit <a title="Corners.js" href="http://www.netzgesta.de/corner/" target="_blank">this page</a> and download &#8220;corner.zip&#8221;. In the zip file, there are few javascript files that you can have some other effects with, but if you just want rounded corners, copy <em>justcorners.js</em> and reference it inside your head tags.</p>

<div class="wp_codebox_msgheader"><span class="codebox_right"><a href="javascript:;" onclick="toggle_collapse('231');">[<span id="231_symbol">-</span>]</a></span><span class="codebox_left"><span id="l23code1"><a href="javascript:;" onclick="javascript:showCodeTxt('23code1'); return false;">View Code</a> HTML</span></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="231"><td class="code" id="23code1"><pre>...
&lt;script src=&quot;http://www.wowebmaster.com/wp-admin/justcorners.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;</pre></td></tr></table></div>

<p>Then, add a class into your image tag as it&#8217;s done in the following code.</p>

<div class="wp_codebox_msgheader"><span class="codebox_right"><a href="javascript:;" onclick="toggle_collapse('232');">[<span id="232_symbol">-</span>]</a></span><span class="codebox_left"><span id="l23code2"><a href="javascript:;" onclick="javascript:showCodeTxt('23code2'); return false;">View Code</a> HTML</span></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="232"><td class="code" id="23code2"><pre>&lt;img class=&quot;corners iradius12&quot; src=&quot;http://www.wowebmaster.com/wp-admin/images/picture.jpg&quot; alt=&quot;&quot; width=&quot;561&quot; height=&quot;353&quot; /&gt;</pre></td></tr></table></div>

<p>Corner radius is set by the second class, which is &#8220;iradius12&#8243; above. If you want greater radius, use highger values after &#8220;iradius&#8221;. <em>e.g. iradius15, iradius25, iradius30&#8230;</em></p>
<p>See more examples at: <a href="http://www.netzgesta.de/corner/">http://www.netzgesta.de/corner/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.wowebmaster.com/javascript/2008/simple-rounded-corners-with-javascript/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Changing MySQL Database Character Set</title>
		<link>http://www.wowebmaster.com/mysql/2008/mysql-character-set-change/</link>
		<comments>http://www.wowebmaster.com/mysql/2008/mysql-character-set-change/#comments</comments>
		<pubDate>Tue, 28 Oct 2008 23:19:10 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Mysql]]></category>

		<category><![CDATA[bash]]></category>

		<category><![CDATA[command line]]></category>

		<guid isPermaLink="false">http://www.wowebmaster.com/?p=22</guid>
		<description><![CDATA[MySQL Database Character Set Problem]]></description>
			<content:encoded><![CDATA[<p>You have probably come across with the mysql character set problem, If you are trying to implement a database in a language other than English. You are inserting rows with your text in your language, but you see invalid characters on your database, phpmyadmin mostly.</p>
<p>This is mostly because of character set defined in your mysql database is not proper for your language. This is usually UTF-8 Unicode, and it is default.</p>
<p><strong>Fix:</strong></p>
<p>Changing the charecter set can be done via mysql command line.  Just login to your server via SSH and bring your mysql command line on with following command.</p>

<div class="wp_codebox_msgheader"><span class="codebox_right"><a href="javascript:;" onclick="toggle_collapse('223');">[<span id="223_symbol">-</span>]</a></span><span class="codebox_left"><span id="l22code3"><a href="javascript:;" onclick="javascript:showCodeTxt('22code3'); return false;">View Code</a> BASH</span></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="223"><td class="code" id="22code3"><pre class="bash"> mysql -h <span style="color: #000000; font-weight: bold;">&lt;</span>hostname<span style="color: #000000; font-weight: bold;">&gt;</span>  -D <span style="color: #000000; font-weight: bold;">&lt;</span>databasename<span style="color: #000000; font-weight: bold;">&gt;</span>  -u <span style="color: #000000; font-weight: bold;">&lt;</span>username<span style="color: #000000; font-weight: bold;">&gt;</span>  -p</pre></td></tr></table></div>

<p>Now it will ask you password before giving access to mysql prompt.</p>

<div class="wp_codebox_msgheader"><span class="codebox_right"><a href="javascript:;" onclick="toggle_collapse('224');">[<span id="224_symbol">-</span>]</a></span><span class="codebox_left"><span id="l22code4"><a href="javascript:;" onclick="javascript:showCodeTxt('22code4'); return false;">View Code</a> BASH</span></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="224"><td class="code" id="22code4"><pre class="bash">ALTER DATABASE wowebmaster DEFAULT CHARACTER SET utf8 COLLATE utf8_turkish_ci \g</pre></td></tr></table></div>

<p>When you get access to mysql command line,  type the above mysql command, it will change the character set of <em>wowebmaster</em> database to utf8_turkish_ci . That&#8217;s it. Replace the database name and the character set for your own modifications.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wowebmaster.com/mysql/2008/mysql-character-set-change/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Auto Refreshing Iframes</title>
		<link>http://www.wowebmaster.com/javascript/2008/auto-refreshing-iframes/</link>
		<comments>http://www.wowebmaster.com/javascript/2008/auto-refreshing-iframes/#comments</comments>
		<pubDate>Tue, 14 Oct 2008 07:46:42 +0000</pubDate>
		<dc:creator>sguler</dc:creator>
		
		<category><![CDATA[Javascript]]></category>

		<category><![CDATA[iframe]]></category>

		<category><![CDATA[refresh]]></category>

		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.wowebmaster.com/?p=21</guid>
		<description><![CDATA[How to auto refresh iframes with javascript]]></description>
			<content:encoded><![CDATA[<p>Quoted from Wikipedia, &#8220;IFrame (from Inline Frame) is an HTML element which makes it possible to embed an HTML document inside another HTML document&#8221;. </p>
<p>If you are using iframes to serve frequently updated feeds on your site, such as a score board, news feed, then you should provide your visitors an iframe updating automaticaly while the page stays same. This is accomplished by a javascript function. You can easily set a time interval to refresh a specific iframe on your page by this way. As a result, your users don&#8217;t have to refresh the whole page every time to update the feed flow.</p>
<p>Put the following function inside head tags on your page.</p>

<div class="wp_codebox_msgheader"><span class="codebox_right"><a href="javascript:;" onclick="toggle_collapse('215');">[<span id="215_symbol">-</span>]</a></span><span class="codebox_left"><span id="l21code5"><a href="javascript:;" onclick="javascript:showCodeTxt('21code5'); return false;">View Code</a> JAVASCRIPT</span></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="215"><td class="code" id="21code5"><pre class="javascript"><span style="color: #66cc66;">&lt;</span>script language=<span style="color: #3366CC;">&quot;javascript&quot;</span><span style="color: #66cc66;">&gt;</span>
<span style="color: #003366; font-weight: bold;">function</span> reloadIt<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
frm=document.<span style="color: #006600;">getElementsByName</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;iframename&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #66cc66;">&#93;</span>;<span style="color: #009900; font-style: italic;">//we get the iframe object named iframename</span>
frm.<span style="color: #006600;">src</span>=frm.<span style="color: #006600;">src</span>;<span style="color: #009900; font-style: italic;">//or you can set the src to a new src.</span>
setTimeout<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;reloadIt()&quot;</span>,<span style="color: #CC0000;">60000</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #009900; font-style: italic;">//the function will run every 60000 miliseconds, or 60 seconds</span>
<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&lt;/</span>script<span style="color: #66cc66;">&gt;</span></pre></td></tr></table></div>

<p>Also put an onload attribute for the body tag, similar to the following:</p>

<div class="wp_codebox_msgheader"><span class="codebox_right"><a href="javascript:;" onclick="toggle_collapse('216');">[<span id="216_symbol">-</span>]</a></span><span class="codebox_left"><span id="l21code6"><a href="javascript:;" onclick="javascript:showCodeTxt('21code6'); return false;">View Code</a> HTML</span></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="216"><td class="code" id="21code6"><pre>&lt;body onload=&quot;reloadIt()&quot;&gt;</pre></td></tr></table></div>

<p>Finally, don&#8217;t forget to name your iframe as it is called in javascript function (&#8221;iframename&#8221; in this example).</p>
<p>An example using this function is a <a href="http://www.goalvideos.tv/live-scores/">football live scores</a> page.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wowebmaster.com/javascript/2008/auto-refreshing-iframes/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Simple Php Cache System</title>
		<link>http://www.wowebmaster.com/php/2008/simple-php-cache-system-to-overcome-server-overloads/</link>
		<comments>http://www.wowebmaster.com/php/2008/simple-php-cache-system-to-overcome-server-overloads/#comments</comments>
		<pubDate>Mon, 02 Jun 2008 13:26:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Featured]]></category>

		<category><![CDATA[Php]]></category>

		<category><![CDATA[error]]></category>

		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.wowebmaster.com/?p=10</guid>
		<description><![CDATA[Php Caching to handle overloads of your popular web site]]></description>
			<content:encoded><![CDATA[<div style="float:left; padding-right:10px"><script type="text/javascript"><!--
google_ad_client = "pub-0272250187292886";
/* 300x250, created 6/17/08 */
google_ad_slot = "9229408432";
google_ad_width = 300;
google_ad_height = 250;
// --></script><br />
<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script></div>
<p><strong>Overload Problem</strong></p>
<p>Server overloads are one of the headaches of webmasters, especially if a popular web site is what we are talking about. It is usually because of lots of queries sent by users to servers. Server can be overloaded with those queries and as a result, responses by server can be very slow.</p>
<p>One thing about this repeated user queries to php servers is that it&#8217;s usually same or similar. Think we have a news blog about economy, and it is updated weekly. Queries to index page is same whole week and the response is exactly same. It&#8217;s news. With every query, server responses the latest news. So why do we query our php server again again, if we know the response already. Why don&#8217;t we save server&#8217;s response as html and send it to user. After next query, we send the saved html file to user, instead of quering and compiling php page.</p>
<p><strong>Solution: PHP Caching</strong>:<br />
Given a time interval, php&#8217;s response can be saved into a directory named <em>/cache/</em> with time information added. Our cache system, checks if there is a saved response of php file in given time interval when a new user sends a query to php page. If there is, no need to compile and translate php page again, our cache system sends the saved copy of the page (cache) to user. If our cached page is old enough, system saves the response of php page again for next queries.</p>
<p>So how do we do that?</p>
<p>First we create a directory named, <em>cache</em> to save all our cached pages. If you have a linux server, change it permissions to 755 which will give write permission to our cache system.</p>
<p>The next step is to form our cache system&#8217;s php code. First, create a php file, named <em>cache.php</em>.<br />
In cache php, we will have two main functions, first will cache our php files and save it into <em>/cache/</em> folder. Second function, is to display the cached page if there is one.</p>
<p><strong>Caching Function</strong></p>

<div class="wp_codebox_msgheader"><span class="codebox_right"><a href="javascript:;" onclick="toggle_collapse('107');">[<span id="107_symbol">-</span>]</a></span><span class="codebox_left"><span id="l10code7"><a href="javascript:;" onclick="javascript:showCodeTxt('10code7'); return false;">View Code</a> PHP</span></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="107"><td class="code" id="10code7"><pre class="php"><span style="color: #000000; font-weight: bold;">function</span> getUrl <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">!</span><span style="color: #000066;">isset</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$_SERVER</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'REQUEST_URI'</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
<span style="color: #ff0000">$url</span> <span style="color: #66cc66;">=</span> <span style="color: #ff0000">$_SERVER</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'REQUEST_URI'</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
<span style="color: #ff0000">$url</span> <span style="color: #66cc66;">=</span> <span style="color: #ff0000">$_SERVER</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'SCRIPT_NAME'</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">;</span>
<span style="color: #ff0000">$url</span> <span style="color: #66cc66;">.=</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">!</span><span style="color: #000066;">empty</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$_SERVER</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'QUERY_STRING'</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>? <span style="color: #ff0000;">'?'</span> <span style="color: #66cc66;">.</span> <span style="color: #ff0000">$_SERVER</span><span style="color: #66cc66;">&#91;</span> <span style="color: #ff0000;">'QUERY_STRING'</span> <span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">:</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">&#125;</span>
<span style="color: #b1b100;">return</span> <span style="color: #ff0000">$url</span><span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">//getUrl gets the queried page with query string</span>
<span style="color: #000000; font-weight: bold;">function</span> cache <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$buffer</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #808080; font-style: italic;">//page's content is $buffer</span>
<span style="color: #ff0000">$url</span> <span style="color: #66cc66;">=</span> getUrl<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #ff0000">$filename</span> <span style="color: #66cc66;">=</span> <span style="color: #000066;">md5</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$url</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">.</span> <span style="color: #ff0000;">'.cache'</span><span style="color: #66cc66;">;</span>
<span style="color: #ff0000">$data</span> <span style="color: #66cc66;">=</span> <span style="color: #000066;">time</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">.</span> <span style="color: #ff0000;">'¦'</span> <span style="color: #66cc66;">.</span> <span style="color: #ff0000">$buffer</span><span style="color: #66cc66;">;</span>
<span style="color: #ff0000">$filew</span> <span style="color: #66cc66;">=</span> <span style="color: #000066;">fopen</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;cache/&quot;</span> <span style="color: #66cc66;">.</span> <span style="color: #ff0000">$filename</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'w'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #000066;">fwrite</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$filew</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000">$data</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #000066;">fclose</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$filew</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #b1b100;">return</span> <span style="color: #ff0000">$buffer</span><span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p><em>getUrl</em> function, is defined to get the queried url. This URL will be encrypted and be the name of cached page in <em>cache</em> folder. <em>Cache</em> function, calls the <em>getUrl</em> function to assign the web page&#8217;s address to <em>$url</em>. After encrypting it using md5 algorithm, time is added in front of the content. Then all the data (<em>time and content</em>) is saved into <em>cache/</em>, also returning the content to output.</p>
<p><strong>Outputting Cache Function</strong></p>

<div class="wp_codebox_msgheader"><span class="codebox_right"><a href="javascript:;" onclick="toggle_collapse('108');">[<span id="108_symbol">-</span>]</a></span><span class="codebox_left"><span id="l10code8"><a href="javascript:;" onclick="javascript:showCodeTxt('10code8'); return false;">View Code</a> PHP</span></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="108"><td class="code" id="10code8"><pre class="php"><span style="color: #000000; font-weight: bold;">function</span> display <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
<span style="color: #ff0000">$url</span> <span style="color: #66cc66;">=</span> getUrl<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #ff0000">$filename</span> <span style="color: #66cc66;">=</span> <span style="color: #000066;">md5</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$url</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">.</span> <span style="color: #ff0000;">'.cache'</span><span style="color: #66cc66;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">!</span><span style="color: #000066;">file_exists</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;cache/&quot;</span> <span style="color: #66cc66;">.</span> <span style="color: #ff0000">$filename</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span><span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">&#125;</span>
<span style="color: #ff0000">$filer</span> <span style="color: #66cc66;">=</span> <span style="color: #000066;">fopen</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;cache/&quot;</span> <span style="color: #66cc66;">.</span> <span style="color: #ff0000">$filename</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'r'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #ff0000">$data</span> <span style="color: #66cc66;">=</span> <span style="color: #000066;">fread</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$filer</span><span style="color: #66cc66;">,</span> <span style="color: #000066;">filesize</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;cache/&quot;</span> <span style="color: #66cc66;">.</span> <span style="color: #ff0000">$filename</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #000066;">fclose</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$filer</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #ff0000">$content</span> <span style="color: #66cc66;">=</span> <span style="color: #000066;">explode</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'¦'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000">$data</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000066;">count</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$content</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">!=</span> <span style="color: #cc66cc;">2</span> OR<span style="color: #66cc66;">!</span><span style="color: #000066;">is_numeric</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$content</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'0'</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span><span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">&#125;</span>
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000066;">time</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">-</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">100</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #ff0000">$content</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'0'</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>  <span style="color: #808080; font-style: italic;">// 100 is the cache time!!!</span>
<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span><span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">&#125;</span>
<span style="color: #000066;">echo</span> <span style="color: #ff0000">$content</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'1'</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">;</span>
<span style="color: #000066;">die</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>In the above code, again the url is encrypted using md5 since all the cache files&#8217; names in cache directory are encrypted as well. Then, cache file is checked if it is in cache directory, if not function returns false. After confirming cache file&#8217;s existance, the time in cache file is checked whether cache is new enough to output. If yes, its content is returned.</p>
<p><strong>Combining Cache and Display Functions</strong></p>

<div class="wp_codebox_msgheader"><span class="codebox_right"><a href="javascript:;" onclick="toggle_collapse('109');">[<span id="109_symbol">-</span>]</a></span><span class="codebox_left"><span id="l10code9"><a href="javascript:;" onclick="javascript:showCodeTxt('10code9'); return false;">View Code</a> PHP</span></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="109"><td class="code" id="10code9"><pre class="php"><span style="color: #000000; font-weight: bold;">function</span> getUrl <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">!</span><span style="color: #000066;">isset</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$_SERVER</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'REQUEST_URI'</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
<span style="color: #ff0000">$url</span> <span style="color: #66cc66;">=</span> <span style="color: #ff0000">$_SERVER</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'REQUEST_URI'</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
<span style="color: #ff0000">$url</span> <span style="color: #66cc66;">=</span> <span style="color: #ff0000">$_SERVER</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'SCRIPT_NAME'</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">;</span>
<span style="color: #ff0000">$url</span> <span style="color: #66cc66;">.=</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">!</span><span style="color: #000066;">empty</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$_SERVER</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'QUERY_STRING'</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>? <span style="color: #ff0000;">'?'</span> <span style="color: #66cc66;">.</span> <span style="color: #ff0000">$_SERVER</span><span style="color: #66cc66;">&#91;</span> <span style="color: #ff0000;">'QUERY_STRING'</span> <span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">:</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">;</span>
&nbsp;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #b1b100;">return</span> <span style="color: #ff0000">$url</span><span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">//getUrl gets the queried page with query string</span>
<span style="color: #000000; font-weight: bold;">function</span> cache <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$buffer</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #808080; font-style: italic;">//page's content is $buffer</span>
<span style="color: #ff0000">$url</span> <span style="color: #66cc66;">=</span> getUrl<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #ff0000">$filename</span> <span style="color: #66cc66;">=</span> <span style="color: #000066;">md5</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$url</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">.</span> <span style="color: #ff0000;">'.cache'</span><span style="color: #66cc66;">;</span>
<span style="color: #ff0000">$data</span> <span style="color: #66cc66;">=</span> <span style="color: #000066;">time</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">.</span> <span style="color: #ff0000;">'¦'</span> <span style="color: #66cc66;">.</span> <span style="color: #ff0000">$buffer</span><span style="color: #66cc66;">;</span>
<span style="color: #ff0000">$filew</span> <span style="color: #66cc66;">=</span> <span style="color: #000066;">fopen</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;cache/&quot;</span> <span style="color: #66cc66;">.</span> <span style="color: #ff0000">$filename</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'w'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #000066;">fwrite</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$filew</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000">$data</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #000066;">fclose</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$filew</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #b1b100;">return</span> <span style="color: #ff0000">$buffer</span><span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> display <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
<span style="color: #ff0000">$url</span> <span style="color: #66cc66;">=</span> getUrl<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #ff0000">$filename</span> <span style="color: #66cc66;">=</span> <span style="color: #000066;">md5</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$url</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">.</span> <span style="color: #ff0000;">'.cache'</span><span style="color: #66cc66;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">!</span><span style="color: #000066;">file_exists</span><span style="color: #66cc66;">&#40;</span>cache_dir <span style="color: #66cc66;">.</span> <span style="color: #ff0000">$filename</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span><span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">&#125;</span>
<span style="color: #ff0000">$filer</span> <span style="color: #66cc66;">=</span> <span style="color: #000066;">fopen</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;cache/&quot;</span> <span style="color: #66cc66;">.</span> <span style="color: #ff0000">$filename</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'r'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #ff0000">$data</span> <span style="color: #66cc66;">=</span> <span style="color: #000066;">fread</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$filer</span><span style="color: #66cc66;">,</span> <span style="color: #000066;">filesize</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;cache/&quot;</span> <span style="color: #66cc66;">.</span> <span style="color: #ff0000">$filename</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #000066;">fclose</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$filer</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #ff0000">$content</span> <span style="color: #66cc66;">=</span> <span style="color: #000066;">explode</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'¦'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000">$data</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000066;">count</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$content</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">!=</span> <span style="color: #cc66cc;">2</span> OR <span style="color: #66cc66;">!</span><span style="color: #000066;">is_numeric</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$content</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'0'</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span><span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">&#125;</span>
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000066;">time</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">-</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">100</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #ff0000">$content</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'0'</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #808080; font-style: italic;">// 100 is the cache time here!!!</span>
<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span><span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">&#125;</span>
<span style="color: #000066;">echo</span> <span style="color: #ff0000">$content</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'1'</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">;</span>
<span style="color: #000066;">die</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">// Display cache (if any)</span>
display<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>  <span style="color: #808080; font-style: italic;">// if it is displayed, die function will end the program here.</span>
&nbsp;
<span style="color: #808080; font-style: italic;">// if no cache, callback cache</span>
<span style="color: #000066;">ob_start</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'cache'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span></pre></td></tr></table></div>

<p><em>Display</em> function is called after defined, it checks if an appropriate cache file exists, if yes, it outputs its content and end the program, if not, <em>cache</em> function is called with <em>ob_start</em> function to store the cache in <em>cache</em> directory.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wowebmaster.com/php/2008/simple-php-cache-system-to-overcome-server-overloads/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Google Adwords Promotion Coupons for New Sign Ups</title>
		<link>http://www.wowebmaster.com/advertising/2008/google-adwords-promotion-coupons-for-new-sign-ups/</link>
		<comments>http://www.wowebmaster.com/advertising/2008/google-adwords-promotion-coupons-for-new-sign-ups/#comments</comments>
		<pubDate>Sun, 01 Jun 2008 22:15:37 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Advertising]]></category>

		<category><![CDATA[coupons]]></category>

		<guid isPermaLink="false">http://www.wowebmaster.com/?p=9</guid>
		<description><![CDATA[The biggest advertising network's $50 promotional coupons for new sign ups]]></description>
			<content:encoded><![CDATA[<div style="float:left; padding-right:10px"><script type="text/javascript"><!--
google_ad_client = "pub-0272250187292886";
/* 300x250, created 6/1/08 */
google_ad_slot = "7199504772";
google_ad_width = 300;
google_ad_height = 250;
// --></script><br />
<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script></div>
<p><strong>Google Adwords Promo Codes</strong><br />
If you aren&#8217;t new to advertising world, you must have heard of Google Adwords probably. If you do think to promote your business online, you should sign-up for Google Adwords and start marketing your online business. However, before signing up, you may want to know Google&#8217;s promotion codes which will save you some money.</p>
<p>Google has been offering $50 valued promotion codes to new sign ups to promote Google Adwords among new business owners. This is known for a while, but the problem is that Google give those coupons to its big marketers and partners to hand out. This means you have to purchase service/item from a web hosting firm or some other partner of Google to get those $50 promotion coupons.</p>
<p>The good thing is we have found some direct links to those promotion pages. It&#8217;s give away of yahoo small business.</p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-0272250187292886";
/* Text link, created 6/14/08 */
google_ad_slot = "5326670998";
google_ad_output = "textlink";
google_ad_format = "ref_text";
google_cpa_choice = ""; // on file
// --></script><br />
<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script><strong>Sign-up with a new e-mail address using this <a style="color:red" href="https://adwords.google.com/select/main?cmd=Login&amp;sourceid=Yh91503">link</a>.</strong></p>
<p>For new promotion codes or broken links, please share your comments using below form.</p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-0272250187292886";
/* 468x60, wowebmaster,adwords */
google_ad_slot = "8185790706";
google_ad_width = 468;
google_ad_height = 60;
google_cpa_choice = ""; // on file
// --></script><br />
<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.wowebmaster.com/advertising/2008/google-adwords-promotion-coupons-for-new-sign-ups/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Basic Bash Commands in Linux</title>
		<link>http://www.wowebmaster.com/linux/2008/basic-bash-commands-in-linux/</link>
		<comments>http://www.wowebmaster.com/linux/2008/basic-bash-commands-in-linux/#comments</comments>
		<pubDate>Sun, 01 Jun 2008 11:56:43 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Featured]]></category>

		<category><![CDATA[Linux]]></category>

		<category><![CDATA[bash]]></category>

		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.wowebmaster.com/?p=8</guid>
		<description><![CDATA[A basic reference to bash commands used in Linux' command line.]]></description>
			<content:encoded><![CDATA[<p>This reference is prepared for webmasters to provide basic knowledge of bash linux commands. You should know these if you are thinking to move to a dedicated server or have already one.</p>
<p><strong>Mkdir - Make directories</strong>:</p>
<p>* <em>Options</em></p>
<ul>
<li>-m, mode=MODE  set permission mode (as in chmod), not rwxrwxrwx - umask</li>
<li>-p, parents  no error if existing, make parent directories as needed</li>
<li>-v, verbose  print a message for each created directory</li>
<li>-help display this help and exit</li>
<li>-version output version information and exit</li>
</ul>
<p>* <em>Usage</em><br />
<code>mkdir -m 777 folder1</code></p>
<p>Above code would create a directory named <em>folder1</em> which can be read, executed and written by all kind of users. The first digit represents the owner, the second represents the group and the third represents other users. The number 7 represents all three types of permission ( read, write and execute), 6 stands for read and write only, 5 stands for read and execute, 4 is read only, 3 is write and execute, 2 is write only, 1 is execute only and 0 is no permissions.</p>
<p><strong>Cd - Change Directories</strong>:</p>
<p>* <em>Usage</em></p>
<p><code>cd folder1</code><br />
The above command would change the current directory to directory named <em>folder1</em>.</p>
<p><code>cd ..</code><br />
The above command would go to parent directory of current directory.</p>
<p><code>cd /</code><br />
The above command would go to root directory regardless which directory you are in.</p>
<p>Mv - Move or Rename Directories &amp; Files:</p>
<p>* <em>Usage</em></p>
<p><code>move testfolder newfolder</code><br />
This command would move/rename <em>testfolder</em> to <em>newfolder</em>.</p>
<p><code>move * /newdir/</code><br />
The above command moves all files and directories in the current directory, including all the contents of those directories, from the current directory to the directory <em>/newdir/</em> .</p>
<p><strong>Pwd - Print Working Directory</strong>:<br />
It shows you the full path to the directory you are currently in.</p>
<p>* <em>Usage</em></p>
<p><code>pwd</code><br />
It would print the following line:<br />
<em>/home/server/mywebsite.com/</em></p>
<p><strong>Rm - Remove Directories</strong>:</p>
<p>* <em>Usage</em></p>
<p><code>rm install</code><br />
<em>Cannot Remove DIRECTORY Is A Directory</em><br />
If you are getting this error, just force it with this command.</p>
<p><code>rm -rf install</code><br />
The above command would remove the whole directory with files and directories in.</p>
<p><strong>Chmod - Change File Access Permissions</strong></p>
<p>* <em>Options</em><br />
-c, &#8211;changes: like verbose but report only when a change is made<br />
&#8211;no-preserve-root: do not treat `/&#8217; specially (the default)<br />
&#8211;preserve-root: fail to operate recursively on `/&#8217;<br />
-f, &#8211;silent, &#8211;quiet: suppress most error messages<br />
-v, verbose: output a diagnostic for every file processed<br />
&#8211;reference=RFILE: use RFILE&#8217;s mode instead of MODE values<br />
-R, &#8211;recursive: change files and directories recursively<br />
&#8211;help: display this help and exit<br />
&#8211;version: output version information and exit</p>
<p>* <em>Usage</em></p>
<p><code>chmod 644 index.htm</code><br />
The above command gives the file read/write by the owner and only read by everyone else.</p>
<p><em>Some Numerical Mod Presentations</em><br />
600 read and write by owner<br />
400 read by owner<br />
040 read by group<br />
004 read by anybody (other)<br />
200 write by owner<br />
020 write by group<br />
002 write by anybody<br />
100 execute by owner<br />
010 execute by group<br />
001 execute by anybody</p>
<p><strong>Ls - Short Listing of Directories &amp; Files</strong>:</p>
<p>* <em>Options</em><br />
-al: detailed listing of files and directories, showing permissions, ownership, size, and time and date stamp.</p>
<p>Just type <em>ls</em> on the command line, and you get the list of files and directories within your current directory.</p>
<p><strong>Cp - Copy Files</strong>:</p>
<p>* <em>Options</em><br />
-i: with this option, you will be prompted before overwriting the file.<br />
-dpr: copy preserving links (-d option), file attributes (-p option), and copy recursively (-r option)</p>
<p>* <em>Usage</em></p>
<p><code>cp -dpr folder1 folder2/</code><br />
The above code would copy the directory <em>folder1</em> with its contents, to the directory under <em>folder2</em>.</p>
<p><em>folder2</em> has now:<br />
<em><br />
anotherfile.html<br />
folder1<br />
</em></p>
<p><strong>Tar &amp; Bzip2 - Archive Compression &amp; Extraction</strong></p>
<p>* <em>Usage</em><br />
<code>tar -c folder/ | bzip2 &gt; folder.tar.bz2</code><br />
The above command compresses <em>folder</em> directory and the following command extracts the compressed archive.</p>
<p><code>bzip2 -dc folder.tar.bz2 | tar -x</code></p>
<p><strong>Gpg - Encryption &amp; Decryption of Files in Linux</strong></p>
<p>* <em>Usage</em><br />
To encrypt and decrypt files you can use the following command:<br />
<code>gpg -c file</code><br />
<code>gpg file.gpg</code></p>
<p><strong>Wget - Download Files from Web</strong></p>
<p>* <em>Options</em><br />
-r: downloads the whole directory<br />
-c: continues the previous download<br />
-b: goes to background execution<br />
-p: path to place the downloaded files</p>
<p>* <em>Usage</em><br />
The following command, downloads the whole directory, going to background after starting the download.<br />
<code>wget -r -b http://www.somedomain.com/files/</code></p>
<p><strong>Slocate - Search &amp; Locate files</strong><br />
This command builds the slocate database. It will take several minutes to complete this command.This command must be used before searching for files, however cron runs this command periodically on most systems.locate whereis Lists all files whose names contain the string &#8220;whereis&#8221;. directory.</p>
<p><strong>Cat - Contents of Files</strong><br />
Sends file contents to standard output. This is a way to list the contents of short files to the screen.</p>
<p><strong>Whereis</strong><br />
Report all known instances of a command.</p>
<p><strong>Wc</strong><br />
Print byte, word, and line counts</p>
<p><strong>Bg</strong><br />
Places the current job (or, by using the alternative form, the specified jobs) in the background, suspending its execution so that a new user prompt appears immediately. Use the jobs command to discover the identities of background jobs.</p>
<p><strong>Cal - month year</strong><br />
Prints a calendar for the specified month of the specified year.</p>
<p><strong>Clear</strong><br />
Clears the terminal screen.</p>
<p><strong>Dmesg</strong><br />
Prints the messages resulting from the most recent system boot.</p>
<p><strong>Fg</strong><br />
Brings the current job (or the specified jobs) to the foreground.</p>
<p><strong>File</strong><br />
Determines and prints a description of the type of each specified file.</p>
<p><strong>Free</strong><br />
Displays the amount of used and free system memory.</p>
<p><strong>Ftp</strong><br />
Opens an FTP connection to the specified host, allowing files to be transferred. The FTP program provides subcommands for accomplishing file transfers.</p>
<p>* <em>Usage</em><br />
<code>ftp hostname</code></p>
<p><strong>Head</strong><br />
Prints the first several lines of each specified file.</p>
<p><strong>Kill</strong> process_ids<br />
Kills the specified processes, sends the specified processes the specified signal (given as a number or name), or prints a list of available signals.</p>
<p>* <em>Usage</em><br />
<code>kill - signal process_ids<br />
kill -l<br />
killall program<br />
killall - signal program<br />
</code></p>
<p><strong>Mail</strong><br />
Launches a simple mail client that permits sending and receiving email messages.</p>
<p><strong>Ping host</strong><br />
Sends an echo request via TCP/IP to the specified host. A response confirms that the host is operational.</p>
<p><strong>Reboot</strong><br />
Reboots the system.</p>
<p><strong>Shutdown</strong><br />
Shuts down the system after the specified number of minutes elapses (requires root privileges). The -r option causes the system to be rebooted once it has shut down.</p>
<p><code>shutdown -r minutes</code></p>
<p><strong>Telnet</strong><br />
Opens a login session on the specified host.</p>
<p><code>telnet host</code></p>
<p><strong>Top - System Resources</strong><br />
Prints a display of system processes that&#8217;s continually updated until the user presses the q key.</p>
<p><strong>Traceroute</strong><br />
Uses echo requests to determine and print a network path to the host.</p>
<p><code>traceroute 1.1.1.1</code></p>
<p><strong>Uptime</strong><br />
Prints the system uptime.</p>
<p><strong>W</strong><br />
Prints the current system users.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wowebmaster.com/linux/2008/basic-bash-commands-in-linux/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Learn PHP by Examples</title>
		<link>http://www.wowebmaster.com/php/2008/learn-php-by-examples/</link>
		<comments>http://www.wowebmaster.com/php/2008/learn-php-by-examples/#comments</comments>
		<pubDate>Thu, 15 May 2008 10:07:38 +0000</pubDate>
		<dc:creator>sguler</dc:creator>
		
		<category><![CDATA[Featured]]></category>

		<category><![CDATA[Php]]></category>

		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.wowebmaster.com/blog/?p=6</guid>
		<description><![CDATA[A PHP teaching series with lots of examples]]></description>
			<content:encoded><![CDATA[<blockquote>
<h4>Contents:</h4>
<ul>
<li><a href="#wphp">What is PHP?</a></li>
<li><a href="#hworld">Hello World Example</a></li>
<li><a href="#variables">Variables</a></li>
<li><a href="#heredoc">Heredoc Strings</a></li>
<li><a href="#operators">Operators</a></li>
<li><a href="#includef">Include Function</a></li>
<li><a href="#ifstatements">IF Statements</a></li>
<li><a href="#switchs">Switch Statements</a></li>
<li><a href="#userfunctions">User Defined Functions</a></li>
<li><a href="#arrays">Arrays</a></li>
<li><a href="#wloops">While Loops</a></li>
<li><a href="#floops">For Loops</a></li>
<li><a href="#formsusage">HTML Forms &#038; Using with PHP</a></li>
<li><a href="#mysqlandphp">MySQL &#038; PHP</a></li>
</ul>
</blockquote>
<p>Since you are here to learn Php by examples, I&#8217;m assuming you have intermediate knowledge of HTML at least. So I will give you examples of easy php scripts that will teach you how php works. First of all, what is PHP ?</p>
<div id="wphp"><strong>What is PHP ?</strong></div>
<p>PHP is a server-side HTML-embedded scripting language, as PHP.net (PHP Homepage) stated. Meaning, PHP is generally embedded into HTML. When someone visits your PHP page, server compiles it and translates to plain HTML, before sending to visitor. Visitor only gets the HTML coded page which is formed by PHP script. That&#8217;s why they call PHP as a Server-Side Scripting Language.</p>
<div><img class="size-full wp-image-7" title="php-server-side" src="http://www.wowebmaster.com/wp-content/uploads/2008/05/php-server-side.gif" alt="Php Server Side Scripting" width="290" height="135" /></div>
<p>Now, you know that you won&#8217;t be able to view your php files using your internet browsers without putting them on a server. You need a server to put your php files. You have two choices, you can form your PC into a server, meaning you can install apache web server software (working as a php-compiler) on your PC or you can buy a php included web hosting server.</p>
<p>* Installing Apache (PHP,MySql) Server on your PC ?<br />
Easy. Just install Xampp (XAMPP is an easy to install Apache distribution containing MySQL, PHP and Perl) on your PC, and your PC will be your own web server. <a href="http://www.apachefriends.org/en/xampp-windows.html" target="_blank">Xampp Installation Link</a></p>
<p>* Web Hosting ?<br />
I suggest you try free web hosting services. Choose your free php hosting service from <a href="http://www.0php.com/free_PHP_hosting.php">this page</a>. Sign-up for free using a subdomain.</p>
<p>Now, we can start if you have a server to test your php files. But before starting, I suggest you install <a href="http://www.adobe.com/products/dreamweaver/">Adobe&#8217;s Dreamweaver</a> which has an easy php-html editor. It is useful for everyone, it will help you much.</p>
<h4><strong>PHP Examples</strong></h4>
<p>Let&#8217;s start learning. Open your text-editor or if you have dreamweaver installed, open a new file selecting Php. Don&#8217;t forget to save your file with the extension &#8220;.php&#8221; before putting into server.</p>
<blockquote><p><code><span style="color: #ff0000;">&lt;?php<br />
?&gt;</span></code></p></blockquote>
<p>This is a very basic php code. Php scripts, start with &#8220;&lt;?php&#8221; tag and end with &#8220;?&gt;&#8221; tag. While your server is reading that line starting with &#8220;&lt;?php&#8221;, it will know that a php script is starting, and it will compile and translate it to html.</p>

<div class="wp_codebox_msgheader"><span class="codebox_right"><a href="javascript:;" onclick="toggle_collapse('610');">[<span id="610_symbol">-</span>]</a></span><span class="codebox_left"><span id="l6code10"><a href="javascript:;" onclick="javascript:showCodeTxt('6code10'); return false;">View Code</a> PHP</span></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="610"><td width="1%" class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="6code10"><pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #808080; font-style: italic;">//this is a comment</span>
<span style="color: #808080; font-style: italic;">/* This is
a multiline
comment */</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>In the above example, you see a commented line. Two slashes defines the following line as a comment. Server will ignore the line and will continue with the next line.</p>
<div id="hworld"><strong>HTML &amp; PHP - Hello World Example</strong></div>
<p>Below code demostrates the use of PHP with HTML. This code will print &#8220;Hello World&#8221; on the line php tag is, which will be inside the Html codes.</p>

<div class="wp_codebox_msgheader"><span class="codebox_right"><a href="javascript:;" onclick="toggle_collapse('611');">[<span id="611_symbol">-</span>]</a></span><span class="codebox_left"><span id="l6code11"><a href="javascript:;" onclick="javascript:showCodeTxt('6code11'); return false;">View Code</a> PHP</span></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="611"><td width="1%" class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code" id="6code11"><pre class="php"><span style="color: #66cc66;">&lt;</span>html<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;</span>head<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;</span>title<span style="color: #66cc66;">&gt;</span>My PHP Page<span style="color: #66cc66;">&lt;/</span>title<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;/</span>head<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;</span>body<span style="color: #66cc66;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000066;">echo</span> <span style="color: #ff0000;">&quot;Hello World!&quot;</span><span style="color: #66cc66;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #66cc66;">&lt;/</span>body<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;</span>html<span style="color: #66cc66;">&gt;</span></pre></td></tr></table></div>

<p>Save this code as &#8220;test.php&#8221;, put it into your server and access it using your internet browser. Server will compile and send you below html code.</p>

<div class="wp_codebox_msgheader"><span class="codebox_right"><a href="javascript:;" onclick="toggle_collapse('612');">[<span id="612_symbol">-</span>]</a></span><span class="codebox_left"><span id="l6code12"><a href="javascript:;" onclick="javascript:showCodeTxt('6code12'); return false;">View Code</a> HTML</span></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="612"><td width="1%" class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code" id="6code12"><pre>&lt;html&gt;
&lt;head&gt;
&lt;title&gt;My First PHP Page&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
Hello World!
&lt;/body&gt;
&lt;/html&gt;</pre></td></tr></table></div>

<p>In that php script, we have printed inside of the quotation marks with php&#8217;s function &#8220;echo&#8221;. Echo is a function that outputs/prints the string defined in quotation marks. You also should know that string in PHP is defined inside quotation marks. In addition to this, pay attention to the semicolon at the end of the echo function. Every statement in php must be ended with semicolons.</p>
<p>A little more in the below example:</p>

<div class="wp_codebox_msgheader"><span class="codebox_right"><a href="javascript:;" onclick="toggle_collapse('613');">[<span id="613_symbol">-</span>]</a></span><span class="codebox_left"><span id="l6code13"><a href="javascript:;" onclick="javascript:showCodeTxt('6code13'); return false;">View Code</a> PHP</span></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="613"><td width="1%" class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code" id="6code13"><pre class="php"><span style="color: #66cc66;">&lt;</span>html<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;</span>head<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;</span>title<span style="color: #66cc66;">&gt;</span>My First PHP Page<span style="color: #66cc66;">&lt;/</span>title<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;/</span>head<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;</span>body<span style="color: #66cc66;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000066;">echo</span> <span style="color: #ff0000;">&quot;&lt;span style=<span style="color: #000099; font-weight: bold;">\&quot;</span>color:red<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;Hello World!&lt;/span&gt;&quot;</span><span style="color: #66cc66;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #66cc66;">&lt;/</span>body<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;/</span>html<span style="color: #66cc66;">&gt;</span></pre></td></tr></table></div>

<p>When the server compiles the above code, it will generate the code below. The reason of using backslash before the quotation mark is to escape from quotation mark. Because first quotation mark starts the string and the second ends the string. If we do not escape from that quotation, the php script leads to an error since there is no function called &#8220;color&#8221; in php which is come after quotation. So we have to define all of the line with span tag and its inside as one <em>string</em>. This is done adding quotation marks at the beginning and also ending of the string. If the string, as in the above example, contains quotation marks, we do escape from that character using backslash (&#8221;\&#8221;).</p>

<div class="wp_codebox_msgheader"><span class="codebox_right"><a href="javascript:;" onclick="toggle_collapse('614');">[<span id="614_symbol">-</span>]</a></span><span class="codebox_left"><span id="l6code14"><a href="javascript:;" onclick="javascript:showCodeTxt('6code14'); return false;">View Code</a> HTML</span></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="614"><td width="1%" class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code" id="6code14"><pre>&lt;html&gt;
&lt;head&gt;
&lt;title&gt;My First PHP Page&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;span style=&quot;color:red&quot;&gt;Hello World!&lt;/span&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></td></tr></table></div>

<div id="variables"><strong>Variables in PHP</strong></div>
<p>Variables in php is defined by the beginning character of &#8220;$&#8221; and followed by the name of variable. Here is an example.</p>

<div class="wp_codebox_msgheader"><span class="codebox_right"><a href="javascript:;" onclick="toggle_collapse('615');">[<span id="615_symbol">-</span>]</a></span><span class="codebox_left"><span id="l6code15"><a href="javascript:;" onclick="javascript:showCodeTxt('6code15'); return false;">View Code</a> PHP</span></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="615"><td width="1%" class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code" id="6code15"><pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #ff0000">$site</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;wowebmaster.com&quot;</span><span style="color: #66cc66;">;</span> <span style="color: #808080; font-style: italic;">// variable is defined as a string</span>
<span style="color: #ff0000">$days_in_week</span><span style="color: #66cc66;">=</span><span style="color: #cc66cc;">7</span><span style="color: #66cc66;">;</span> <span style="color: #808080; font-style: italic;">// variable</span>
<span style="color: #ff0000">$weeks</span><span style="color: #66cc66;">=</span><span style="color: #cc66cc;">5</span><span style="color: #66cc66;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>In the above code, there are three variables defined: site, days_in_week and weeks. Those are defined but will not printed unless you call and output them somewhere in your script. Here is an example demonstrating how we use them.</p>

<div class="wp_codebox_msgheader"><span class="codebox_right"><a href="javascript:;" onclick="toggle_collapse('616');">[<span id="616_symbol">-</span>]</a></span><span class="codebox_left"><span id="l6code16"><a href="javascript:;" onclick="javascript:showCodeTxt('6code16'); return false;">View Code</a> PHP</span></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="616"><td width="1%" class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code" id="6code16"><pre class="php"><span style="color: #66cc66;">&lt;</span>html<span style="color: #66cc66;">&gt;&lt;</span>head<span style="color: #66cc66;">&gt;&lt;</span>title<span style="color: #66cc66;">&gt;</span>Variables in PHP<span style="color: #66cc66;">&lt;/</span>title<span style="color: #66cc66;">&gt;&lt;/</span>head<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;</span>body<span style="color: #66cc66;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #ff0000">$site</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;mydomain.com&quot;</span><span style="color: #66cc66;">;</span> <span style="color: #808080; font-style: italic;">// variable is defined as a string</span>
<span style="color: #ff0000">$days_in_week</span><span style="color: #66cc66;">=</span><span style="color: #cc66cc;">7</span><span style="color: #66cc66;">;</span> <span style="color: #808080; font-style: italic;">// variable</span>
<span style="color: #ff0000">$weeks</span><span style="color: #66cc66;">=</span><span style="color: #cc66cc;">5</span><span style="color: #66cc66;">;</span>
<span style="color: #ff0000">$total</span><span style="color: #66cc66;">=</span><span style="color: #ff0000">$weeks</span> <span style="color: #66cc66;">*</span> <span style="color: #ff0000">$days_in_week</span><span style="color: #66cc66;">;</span>
<span style="color: #000066;">echo</span> <span style="color: #ff0000">$site</span><span style="color: #66cc66;">.</span><span style="color: #ff0000;">&quot; has been established &quot;</span><span style="color: #66cc66;">.</span><span style="color: #ff0000">$total</span><span style="color: #66cc66;">.</span><span style="color: #ff0000;">&quot; days ago&quot;</span><span style="color: #66cc66;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #66cc66;">&lt;/</span>body<span style="color: #66cc66;">&gt;&lt;/</span>html<span style="color: #66cc66;">&gt;</span></pre></td></tr></table></div>

<p>Two things are new to you at the above code. First, we defined a new variable multiplying two other variables. Multiplying numbers is done with &#8220;*&#8221; (Multiply) sign in php. The second one is inside of the echo function. We have combined three strings and printed. As you see, combining/joining two or mor variables is done by adding dots (.) besides of the variables. We may define a new variable by doing this. See this:</p>

<div class="wp_codebox_msgheader"><span class="codebox_right"><a href="javascript:;" onclick="toggle_collapse('617');">[<span id="617_symbol">-</span>]</a></span><span class="codebox_left"><span id="l6code17"><a href="javascript:;" onclick="javascript:showCodeTxt('6code17'); return false;">View Code</a> PHP</span></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="617"><td width="1%" class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="6code17"><pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #ff0000">$firstname</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Britney&quot;</span><span style="color: #66cc66;">;</span>
<span style="color: #ff0000">$sirname</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot; Spears&quot;</span><span style="color: #66cc66;">;</span>
<span style="color: #ff0000">$name</span><span style="color: #66cc66;">=</span> <span style="color: #ff0000">$firstname</span><span style="color: #66cc66;">.</span><span style="color: #ff0000">$sirname</span><span style="color: #66cc66;">;</span> <span style="color: #808080; font-style: italic;">//joining with a dot</span>
<span style="color: #000066;">echo</span> <span style="color: #ff0000">$name</span><span style="color: #66cc66;">;</span> <span style="color: #808080; font-style: italic;">//no quotation, name variable is already a string</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<div id="heredoc"><strong>Heredoc String Creation</strong></div>
<p>There is an alternative way of defining strings in php. It is done by heredoc tool. Heredoc&#8217;s syntax is &lt;&lt;&lt;. After this operator, an identifier is provided, then a newline. The string itself follows, and then the same identifier again to close the quotation. Here is an example:</p>

<div class="wp_codebox_msgheader"><span class="codebox_right"><a href="javascript:;" onclick="toggle_collapse('618');">[<span id="618_symbol">-</span>]</a></span><span class="codebox_left"><span id="l6code18"><a href="javascript:;" onclick="javascript:showCodeTxt('6code18'); return false;">View Code</a> PHP</span></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="618"><td width="1%" class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code" id="6code18"><pre class="php"><span style="color: #66cc66;">&lt;</span>html<span style="color: #66cc66;">&gt;&lt;</span>head<span style="color: #66cc66;">&gt;&lt;</span>title<span style="color: #66cc66;">&gt;</span>Variables in PHP<span style="color: #66cc66;">&lt;/</span>title<span style="color: #66cc66;">&gt;&lt;/</span>head<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;</span>body<span style="color: #66cc66;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #ff0000">$str</span> <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">&lt;&lt;&lt;</span>EOD
<<span style="color: #66cc66;">|!</span>REG3XP0<span style="color: #66cc66;">!</span>>Example of string
spanning multiple lines
using heredoc syntax<span style="color: #66cc66;">.|</span>>
EOD<span style="color: #66cc66;">;</span>
<span style="color: #000066;">echo</span> <span style="color: #ff0000">$string</span><span style="color: #66cc66;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #66cc66;">&lt;/</span>body<span style="color: #66cc66;">&gt;&lt;/</span>html<span style="color: #66cc66;">&gt;</span></pre></td></tr></table></div>

<p>This code will be translated to the below code by the php server.</p>

<div class="wp_codebox_msgheader"><span class="codebox_right"><a href="javascript:;" onclick="toggle_collapse('619');">[<span id="619_symbol">-</span>]</a></span><span class="codebox_left"><span id="l6code19"><a href="javascript:;" onclick="javascript:showCodeTxt('6code19'); return false;">View Code</a> HTML</span></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="619"><td width="1%" class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="6code19"><pre>&lt;html&gt;&lt;head&gt;&lt;title&gt;Variables in PHP&lt;/title&gt;&lt;/head&gt;
&lt;body&gt;
Example of string
spanning multiple lines
using heredoc syntax.
&lt;/body&gt;&lt;/html&gt;</pre></td></tr></table></div>

<div id="operators"><strong>PHP Operators</strong></div>
<p>* Assignment Operators:<br />
Equal character, &#8220;=&#8221;, is used to assign variables,values or strings to variables.<br />
- $my_var=$your_var;</p>
<p>* Arithmetic Operators</p>
<ul>
<li>Addition +</li>
<li>Subtraction -</li>
<li>Multiplication *</li>
<li>Division /</li>
<li>Modulus %</li>
</ul>
<p>Here is an example:</p>

<div class="wp_codebox_msgheader"><span class="codebox_right"><a href="javascript:;" onclick="toggle_collapse('620');">[<span id="620_symbol">-</span>]</a></span><span class="codebox_left"><span id="l6code20"><a href="javascript:;" onclick="javascript:showCodeTxt('6code20'); return false;">View Code</a> PHP</span></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="620"><td width="1%" class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></td><td class="code" id="6code20"><pre class="php"><span style="color: #66cc66;">&lt;</span>html<span style="color: #66cc66;">&gt;&lt;</span>head<span style="color: #66cc66;">&gt;&lt;</span>title<span style="color: #66cc66;">&gt;</span>Variables in PHP<span style="color: #66cc66;">&lt;/</span>title<span style="color: #66cc66;">&gt;&lt;/</span>head<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;</span>body<span style="color: #66cc66;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #ff0000">$var1</span><span style="color: #66cc66;">=</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">;</span>
<span style="color: #ff0000">$var2</span><span style="color: #66cc66;">=</span><span style="color: #cc66cc;">5</span><span style="color: #66cc66;">;</span>
<span style="color: #ff0000">$total</span><span style="color: #66cc66;">=</span><span style="color: #ff0000">$var1</span> <span style="color: #66cc66;">+</span> <span style="color: #ff0000">$var2</span><span style="color: #66cc66;">;</span>
<span style="color: #ff0000">$diff</span><span style="color: #66cc66;">=</span><span style="color: #ff0000">$var2</span> <span style="color: #66cc66;">-</span> <span style="color: #ff0000">$var1</span><span style="color: #66cc66;">;</span>
<span style="color: #ff0000">$mul</span><span style="color: #66cc66;">=</span><span style="color: #ff0000">$total</span> <span style="color: #66cc66;">*</span> <span style="color: #ff0000">$diff</span><span style="color: #66cc66;">;</span>
<span style="color: #ff0000">$div</span><span style="color: #66cc66;">=</span><span style="color: #ff0000">$total</span> <span style="color: #66cc66;">/</span> <span style="color: #ff0000">$var1</span><span style="color: #66cc66;">;</span>
<span style="color: #ff0000">$mod</span><span style="color: #66cc66;">=</span><span style="color: #ff0000">$total</span> <span style="color: #66cc66;">%</span> <span style="color: #ff0000">$var2</span><span style="color: #66cc66;">;</span>
<span style="color: #808080; font-style: italic;">// now outputting as string!</span>
<span style="color: #000066;">echo</span> <span style="color: #66cc66;">&lt;&lt;&lt;</span>TEST
<span style="color: #0000ff;">total is <span style="color: #ff0000">$total</span> <span style="color: #66cc66;">&lt;</span>br<span style="color: #66cc66;">/&gt;</span>
diff is <span style="color: #ff0000">$diff</span> <span style="color: #66cc66;">&lt;</span>br<span style="color: #66cc66;">/&gt;</span>
mul is <span style="color: #ff0000">$mul</span> <span style="color: #66cc66;">&lt;</span>br<span style="color: #66cc66;">/&gt;</span>
div is <span style="color: #ff0000">$div</span> <span style="color: #66cc66;">&lt;</span>br<span style="color: #66cc66;">/&gt;</span>
mod is <span style="color: #ff0000">$mod</span> <span style="color: #66cc66;">&lt;</span>br<span style="color: #66cc66;">/&gt;|</span>>
TEST<span style="color: #66cc66;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #66cc66;">&lt;/</span>body<span style="color: #66cc66;">&gt;&lt;/</span>html<span style="color: #66cc66;">&gt;</span></pre></td></tr></table></div>

<p>The server will output the below code.</p>

<div class="wp_codebox_msgheader"><span class="codebox_right"><a href="javascript:;" onclick="toggle_collapse('621');">[<span id="621_symbol">-</span>]</a></span><span class="codebox_left"><span id="l6code21"><a href="javascript:;" onclick="javascript:showCodeTxt('6code21'); return false;">View Code</a> HTML</span></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="621"><td width="1%" class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="6code21"><pre>&lt;html&gt;&lt;head&gt;&lt;title&gt;Variables in PHP&lt;/title&gt;&lt;/head&gt;
&lt;body&gt;total is 6 &lt;br/&gt;
diff is 4 &lt;br/&gt;
mul is 24 &lt;br/&gt;
div is 6 &lt;br/&gt;
mod is 1 &lt;br/&gt;&lt;/body&gt;&lt;/html&gt;</pre></td></tr></table></div>

<p>*Comparison Operators</p>
<table style="height: 130px;" border="1" cellspacing="1" cellpadding="1" width="100%" align="left">
<tbody>
<tr>
<th>Operator</th>
<th>English</th>
<th>Example</th>
<th>Result</th>
</tr>
<tr>
<td>==</td>
<td>Equal To</td>
<td>$x == $y</td>
<td>false</td>
</tr>
<tr>
<td>!=</td>
<td>Not Equal To</td>
<td>$x != $y</td>
<td>true</td>
</tr>
<tr>
<td>&lt;</td>
<td>Less Than</td>
<td>$x &lt; $y</td>
<td>true</td>
</tr>
<tr>
<td>&gt;</td>
<td>Greater Than</td>
<td>$x &gt; $y</td>
<td>false</td>
</tr>
<tr>
<td>&lt;=</td>
<td>Less Than or Equal To</td>
<td>$x &lt;= $y</td>
<td>true</td>
</tr>
<tr>
<td>&gt;=</td>
<td>Greater Than or Equal To</td>
<td>$x &gt;= $y</td>
<td>false</td>
</tr>
</tbody>
</table>
<div style="clear:both">Comparison operators are used for checking relationships of two variables or values. The result will be in true/false type. We&#8217;ll see the use of comparison operators later.</div>
<p>*Other Operators</p>
<table border="1" cellspacing="1" cellpadding="1" width="100%" align="left">
<tbody>
<tr>
<th>Operator</th>
<th>English</th>
<th>Example</th>
<th>Equivalent Operation</th>
</tr>
<tr>
<td>+=</td>
<td>Plus Equals</td>
<td>$x += 2;</td>
<td>$x = $x + 2;</td>
</tr>
<tr>
<td>-=</td>
<td>Minus Equals</td>
<td>$x -= 4;</td>
<td>$x = $x - 4;</td>
</tr>
<tr>
<td>*=</td>
<td>Multiply Equals</td>
<td>$x *= 3;</td>
<td>$x = $x * 3;</td>
</tr>
<tr>
<td>/=</td>
<td>Divide Equals</td>
<td>$x /= 2;</td>
<td>$x = $x / 2;</td>
</tr>
<tr>
<td>%=</td>
<td>Modulo Equals</td>
<td>$x %= 5;</td>
<td>$x = $x % 5;</td>
</tr>
<tr>
<td>.=</td>
<td>Concatenate Equals</td>
<td>$my_str.=&#8221;hello&#8221;;</td>
<td>$my_str = $my_str . &#8220;hello&#8221;;</td>
</tr>
<tr>
<td>++</td>
<td>Increment</td>
<td>$x++;</td>
<td>$x = $x + $x;</td>
</tr>
<tr>
<td>++</td>
<td>Decrement</td>
<td>$x&#8211;;</td>
<td>$x = $x - $x;</td>
</tr>
</tbody>
</table>
<div style="clear:both"></div>
<div id="includef"><strong>Include Function</strong></div>
<p>PHP&#8217;s <em>include</em> is one of the most widely used functions. It simply, inserts the file defined into the php script. Meaning, you can use variables, functions and classes of the inserted file in your php script. Here is a simple example that will explain you more.</p>
<p><strong>vars.php:</strong></p>

<div class="wp_codebox_msgheader"><span class="codebox_right"><a href="javascript:;" onclick="toggle_collapse('622');">[<span id="622_symbol">-</span>]</a></span><span class="codebox_left"><span id="l6code22"><a href="javascript:;" onclick="javascript:showCodeTxt('6code22'); return false;">View Code</a> PHP</span></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="622"><td width="1%" class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="6code22"><pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #ff0000">$site_name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;WoWebmaster.com&quot;</span><span style="color: #66cc66;">;</span>
<span style="color: #ff0000">$greeting</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Guest, Welcome to &quot;</span><span style="color: #66cc66;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p><strong>index.php:</strong></p>

<div class="wp_codebox_msgheader"><span class="codebox_right"><a href="javascript:;" onclick="toggle_collapse('623');">[<span id="623_symbol">-</span>]</a></span><span class="codebox_left"><span id="l6code23"><a href="javascript:;" onclick="javascript:showCodeTxt('6code23'); return false;">View Code</a> PHP</span></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="623"><td width="1%" class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="6code23"><pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">include</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;vars.php&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #000066;">echo</span> <span style="color: #ff0000">$greeting</span><span style="color: #66cc66;">.</span><span style="color: #ff0000">$site_name</span><span style="color: #66cc66;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Output of index.php would be following html code.</p>

<div class="wp_codebox_msgheader"><span class="codebox_right"><a href="javascript:;" onclick="toggle_collapse('624');">[<span id="624_symbol">-</span>]</a></span><span class="codebox_left"><span id="l6code24"><a href="javascript:;" onclick="javascript:showCodeTxt('6code24'); return false;">View Code</a> HTML</span></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="624"><td width="1%" class="line_numbers"><pre>1
</pre></td><td class="code" id="6code24"><pre>Guest, Welcome to WoWebmaster.com</pre></td></tr></table></div>

<p>As you see, we used the variable defined in vars.php by including it in index.php.</p>
<div id="ifstatements"><strong>IF Statements</strong></div>

<div class="wp_codebox_msgheader"><span class="codebox_right"><a href="javascript:;" onclick="toggle_collapse('625');">[<span id="625_symbol">-</span>]</a></span><span class="codebox_left"><span id="l6code25"><a href="javascript:;" onclick="javascript:showCodeTxt('6code25'); return false;">View Code</a> PHP</span></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="625"><td width="1%" class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code" id="6code25"><pre class="php"><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>condition1<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
statement1<span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #66cc66;">&#40;</span>condition2<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
statement2<span style="color: #66cc66;">;</span>
<span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
statement3<span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">&#125;</span>
nextline<span style="color: #66cc66;">;</span></pre></td></tr></table></div>

<p>If statements, also, are one of the most widely used constructs of programming languages. If construct, is the important part of decision making algorithms. It allows conditional code execution. It checks whether a condition is true and the statement inside the construct is executed depending on the condition.</p>
<p>In the illustration above, <em>if</em> construct checks whether <em>condition1</em> is true, if so, <em>statement1</em> is executed, then <em>statement2</em> and <em>statement3</em> is ignored and the program jumps out of <em>if</em> construct, executing next line.</p>
<p>If <em>condition1</em> is false, then <em>condition2</em> is checked, if it is true, only <em>statement2</em> is executed before jumping to <em>nextline</em> statement. If <em>condition2</em> is also false, only <em>statement3</em> is executed.</p>
<p>An Example:</p>

<div class="wp_codebox_msgheader"><span class="codebox_right"><a href="javascript:;" onclick="toggle_collapse('626');">[<span id="626_symbol">-</span>]</a></span><span class="codebox_left"><span id="l6code26"><a href="javascript:;" onclick="javascript:showCodeTxt('6code26'); return false;">View Code</a> PHP</span></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="626"><td width="1%" class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code" id="6code26"><pre class="php"><span style="color: #66cc66;">&lt;</span>html<span style="color: #66cc66;">&gt;&lt;</span>head<span style="color: #66cc66;">&gt;&lt;</span>title<span style="color: #66cc66;">&gt;</span>Variables in PHP<span style="color: #66cc66;">&lt;/</span>title<span style="color: #66cc66;">&gt;&lt;/</span>head<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;</span>body<span style="color: #66cc66;">&gt;&lt;</span>?php
<span style="color: #ff0000">$who</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;user&quot;</span><span style="color: #66cc66;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000">$who</span> <span style="color: #66cc66;">==</span> <span style="color: #ff0000;">&quot;guest&quot;</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
<span style="color: #000066;">echo</span> <span style="color: #ff0000;">&quot;Subscribe to our newsletter!&quot;</span><span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">&#125;</span>
<span style="color: #b1b100;">elseif</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000">$who</span> <span style="color: #66cc66;">==</span> <span style="color: #ff0000;">&quot;user&quot;</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
<span style="color: #000066;">echo</span> <span style="color: #ff0000;">&quot;Welcome!&quot;</span><span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">&#125;</span>
<span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
<span style="color: #000066;">echo</span> <span style="color: #ff0000;">&quot;Who are you?&quot;</span><span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">&#125;</span>
?<span style="color: #66cc66;">&gt;&lt;/</span>span<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;/</span>body<span style="color: #66cc66;">&gt;&lt;/</span>html<span style="color: #66cc66;">&gt;</span></pre></td></tr></table></div>

<p>Now we will explain the example line by line. We defined a <em>$who</em> variable on the first line. It is a string containing &#8220;user&#8221;. In the second line, an <em>if</em> construct is defined. First condition to check is inside the first parenthesis which has <em>$who == &#8220;guest&#8221;</em> condition. If the variable, <em>$who</em>, equals to &#8220;quest&#8221;, then the statement defined inside the brackets is executed and without checking other conditions, program jumps out of <em>if</em> statements. In the example, <em>$who</em> does not equal to &#8220;guest&#8221;, instead, it equals to &#8220;user&#8221;. As a result, only <em>elseif</em> construct&#8217;s condition is executed, which outputs a &#8220;Welcome&#8221; on the screen.</p>
<p>Another Example:<br />
<strong>values.php:</strong></p>

<div class="wp_codebox_msgheader"><span class="codebox_right"><a href="javascript:;" onclick="toggle_collapse('627');">[<span id="627_symbol">-</span>]</a></span><span class="codebox_left"><span id="l6code27"><a href="javascript:;" onclick="javascript:showCodeTxt('6code27'); return false;">View Code</a> PHP</span></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="627"><td width="1%" class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="6code27"><pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #ff0000">$var</span><span style="color: #66cc66;">=</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p><strong>index.php:</strong></p>

<div class="wp_codebox_msgheader"><span class="codebox_right"><a href="javascript:;" onclick="toggle_collapse('628');">[<span id="628_symbol">-</span>]</a></span><span class="codebox_left"><span id="l6code28"><a href="javascript:;" onclick="javascript:showCodeTxt('6code28'); return false;">View Code</a> PHP</span></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="628"><td width="1%" class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code" id="6code28"><pre class="php"><span style="color: #66cc66;">&lt;</span>html<span style="color: #66cc66;">&gt;&lt;</span>head<span style="color: #66cc66;">&gt;&lt;</span>title<span style="color: #66cc66;">&gt;</span>Variables in PHP<span style="color: #66cc66;">&lt;/</span>title<span style="color: #66cc66;">&gt;&lt;/</span>head<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;</span>body<span style="color: #66cc66;">&gt;&lt;</span>?php
<span style="color: #b1b100;">include</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;values.php&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000">$var</span> <span style="color: #66cc66;">==</span> <span style="color: #cc66cc;">0</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
<span style="color: #000066;">echo</span> <span style="color: #ff0000;">&quot;Value isn't 0.&quot;</span><span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">&#125;</span>
<span style="color: #b1b100;">elseif</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000">$var</span> <span style="color: #66cc66;">==</span> <span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
<span style="color: #000066;">echo</span> <span style="color: #ff0000;">&quot;Value is not 1.&quot;</span><span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">&#125;</span>
<span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
<span style="color: #000066;">echo</span> <span style="color: #ff0000;">&quot;No, the value is &quot;</span><span style="color: #66cc66;">.</span><span style="color: #ff0000">$var</span><span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #66cc66;">&lt;/</span>body<span style="color: #66cc66;">&gt;&lt;/</span>html<span style="color: #66cc66;">&gt;</span></pre></td></tr></table></div>

<p>In the example above, first, the program will check whether <em>$var</em> is 0, which is false, then the program will check the second condition which is also false. Since both conditions are not met, the program will only execute the last statement which is inside of <em>else</em> statement&#8217;s brackets. Following code is the output of the above code.</p>

<div class="wp_codebox_msgheader"><span class="codebox_right"><a href="javascript:;" onclick="toggle_collapse('629');">[<span id="629_symbol">-</span>]</a></span><span class="codebox_left"><span id="l6code29"><a href="javascript:;" onclick="javascript:showCodeTxt('6code29'); return false;">View Code</a> HTML</span></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="629"><td width="1%" class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="6code29"><pre>&lt;html&gt;&lt;head&gt;&lt;title&gt;Variables in PHP&lt;/title&gt;&lt;/head&gt;
&lt;body&gt;
No, the value is 3
&lt;/body&gt;&lt;/html&gt;</pre></td></tr></table></div>

<div id="switchs"><strong>Switch Statements</strong></div>
<p>Switch is an alternative way of condition checking. With Switch statements, you can compare a same variable (or expression) against different cases quickly instead of using lots of elseif statements. Again, we will illustrate the use of it with an example:</p>

<div class="wp_codebox_msgheader"><span class="codebox_right"><a href="javascript:;" onclick="toggle_collapse('630');">[<span id="630_symbol">-</span>]</a></span><span class="codebox_left"><span id="l6code30"><a href="javascript:;" onclick="javascript:showCodeTxt('6code30'); return false;">View Code</a> PHP</span></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="630"><td width="1%" class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code" id="6code30"><pre class="php"><span style="color: #66cc66;">&lt;</span>html<span style="color: #66cc66;">&gt;&lt;</span>head<span style="color: #66cc66;">&gt;&lt;</span>title<span style="color: #66cc66;">&gt;</span>Variables in PHP<span style="color: #66cc66;">&lt;/</span>title<span style="color: #66cc66;">&gt;&lt;</span>head<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;</span>body<span style="color: #66cc66;">&gt;&lt;</span>?php
<span style="color: #ff0000">$period</span> <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">&quot;morning&quot;</span><span style="color: #66cc66;">;</span>
<span style="color: #b1b100;">switch</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$period</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span> <span style="color: #808080; font-style: italic;">//switch statement checks $period</span>
<span style="color: #b1b100;">case</span> <span style="color: #ff0000;">&quot;morning&quot;</span><span style="color: #66cc66;">:</span>
<span style="color: #000066;">echo</span> <span style="color: #ff0000;">&quot;Good Morning!&quot;</span><span style="color: #66cc66;">;</span>
<span style="color: #b1b100;">break</span><span style="color: #66cc66;">;</span>
<span style="color: #b1b100;">case</span> <span style="color: #ff0000;">&quot;noon&quot;</span><span style="color: #66cc66;">:</span>
<span style="color: #000066;">echo</span> <span style="color: #ff0000;">&quot;Good Afternoon!&quot;</span><span style="color: #66cc66;">;</span>
<span style="color: #b1b100;">break</span><span style="color: #66cc66;">;</span>
<span style="color: #b1b100;">case</span> <span style="color: #ff0000;">&quot;Night&quot;</span><span style="color: #66cc66;">:</span>
<span style="color: #000066;">echo</span> <span style="color: #ff0000;">&quot;Good Evening!&quot;</span><span style="color: #66cc66;">;</span>
<span style="color: #b1b100;">break</span><span style="color: #66cc66;">;</span>
<span style="color: #000000; font-weight: bold;">default</span><span style="color: #66cc66;">:</span>
<span style="color: #000066;">echo</span> <span style="color: #ff0000;">&quot;Have a nice day!&quot;</span><span style="color: #66cc66;">;</span>
<span style="color: #b1b100;">break</span><span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #66cc66;">&lt;/</span>body<span style="color: #66cc66;">&gt;&lt;/</span>html<span style="color: #66cc66;">&gt;</span></pre></td></tr></table></div>

<p><em>Switch</em> statements compares a variable against cases defined, if one <em>case</em> is exactly the same with the variable, then only the statement under that <em>case</em> is executed. If no <em>case</em> equals to the variable then the statement under <em>default</em> line is executed. If you don&#8217;t write a break statement at the end of a case&#8217;s statement list, PHP will go on executing the statements of the following case.</p>
<div id="userfunctions"><strong>User Defined Functions</strong></div>
<p>Function is the name that is given to a special block of statements, when called, the block of statements are executed. Every function has a name, which you can call that special function anywhere in your script after defined.<br />
Defining a function:</p>

<div class="wp_codebox_msgheader"><span class="codebox_right"><a href="javascript:;" onclick="toggle_collapse('631');">[<span id="631_symbol">-</span>]</a></span><span class="codebox_left"><span id="l6code31"><a href="javascript:;" onclick="javascript:showCodeTxt('6code31'); return false;">View Code</a> PHP</span></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="631"><td width="1%" class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="6code31"><pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">function</span> <span style="color: #66cc66;">&lt;</span>em<span style="color: #66cc66;">&gt;</span>function_name<span style="color: #66cc66;">&lt;/</span>em<span style="color: #66cc66;">&gt;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
<span style="color: #66cc66;">&#125;</span>
?<span style="color: #66cc66;">&amp;</span>gt<span style="color: #66cc66;">;</span></pre></td></tr></table></div>

<p>Functions are usually used with parameters. Parameters appear in parantheses which is come after the function name and they can be used in the statements that function includes. Here is a usage example:<br />
<strong>index.php</strong>:</p>

<div class="wp_codebox_msgheader"><span class="codebox_right"><a href="javascript:;" onclick="toggle_collapse('632');">[<span id="632_symbol">-</span>]</a></span><span class="codebox_left"><span id="l6code32"><a href="javascript:;" onclick="javascript:showCodeTxt('6code32'); return false;">View Code</a> PHP</span></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="632"><td width="1%" class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code" id="6code32"><pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #ff0000">$var</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;world of webmaster&quot;</span><span style="color: #66cc66;">;</span>
<span style="color: #000000; font-weight: bold;">function</span> printing <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$text</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
<span style="color: #000066;">echo</span> <span style="color: #ff0000;">&quot;:) &quot;</span><span style="color: #66cc66;">.</span><span style="color: #ff0000">$text</span><span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">&#125;</span>
printing<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$var</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span> <span style="color: #808080; font-style: italic;">// calling our function with the parameter $var</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>output:<br />
<code>:) world of webmaster</code></p></blockquote>
<p>As seen above, the variable <em>$var</em> is defined as a parameter of <em>printing</em> function. This is done in the last line of the php script, <em>printing</em> function is called with the parameter <em>$var</em>. When called, the <em>printing</em> function accesses the value of <em>$var</em> using <em>$text</em> variable.</p>
<p>Some examples with the outputs below:<br />
<strong>functions.php</strong>:</p>

<div class="wp_codebox_msgheader"><span class="codebox_right"><a href="javascript:;" onclick="toggle_collapse('633');">[<span id="633_symbol">-</span>]</a></span><span class="codebox_left"><span id="l6code33"><a href="javascript:;" onclick="javascript:showCodeTxt('6code33'); return false;">View Code</a> PHP</span></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="633"><td width="1%" class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code" id="6code33"><pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">function</span> calc <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$tshirt</span><span style="color: #66cc66;">,</span><span style="color: #ff0000">$number</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
<span style="color: #ff0000">$subtotal</span><span style="color: #66cc66;">=</span><span style="color: #ff0000">$tshirt</span> <span style="color: #66cc66;">*</span> <span style="color: #ff0000">$number</span><span style="color: #66cc66;">;</span> <span style="color: #808080; font-style: italic;">//sub-total price is calculated</span>
<span style="color: #ff0000">$plustaxes</span><span style="color: #66cc66;">=</span> <span style="color: #ff0000">$subtotal</span> <span style="color: #66cc66;">*</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">110</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">100</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span> <span style="color: #808080; font-style: italic;">// plus 10% tax</span>
<span style="color: #000066;">echo</span> <span style="color: #ff0000;">&quot;In Total: <span style="color: #000099; font-weight: bold;">\$</span>&quot;</span><span style="color: #66cc66;">.</span><span style="color: #ff0000">$plustaxes</span><span style="color: #66cc66;">;</span> <span style="color: #808080; font-style: italic;">// don't forget a backslash to escape from dollar sign</span>
<span style="color: #66cc66;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p><strong>index.php</strong></p>

<div class="wp_codebox_msgheader"><span class="codebox_right"><a href="javascript:;" onclick="toggle_collapse('634');">[<span id="634_symbol">-</span>]</a></span><span class="codebox_left"><span id="l6code34"><a href="javascript:;" onclick="javascript:showCodeTxt('6code34'); return false;">View Code</a> PHP</span></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="634"><td width="1%" class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code" id="6code34"><pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">include</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;functions.php&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
calc<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">5</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span> <span style="color: #808080; font-style: italic;">// calc called. 5 tshirts, $11 each.Total price will be</span>
<span style="color: #808080; font-style: italic;">//calculated and printed</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p><strong>the output:</strong><br />
<code>In Total: $60.50</code></p></blockquote>
<p>In the example above, we created a file, &#8220;functions.php&#8221;, that contain <em>calc</em> function. Our aim is to calculate the total price of a purchase. To simplify things, the purchase only comprises of tshirts. Our function <em>calc</em> has two parameters. First is tshirt&#8217;s price (<em>$tshirt</em>) and the second parameter is number of tshirts purchased (<em>$number</em>). Our <em>calc</em> function simply multiplies numbers by tshirt price and then adds the 10% tax.</p>
<p><strong>Functions Returning Values</strong><br />
Functions can also return values to the user. This is accomplished by adding &#8220;return <em>variable</em>;&#8221; at the end of the function. It&#8217;s easy, here is an example:</p>

<div class="wp_codebox_msgheader"><span class="codebox_right"><a href="javascript:;" onclick="toggle_collapse('635');">[<span id="635_symbol">-</span>]</a></span><span class="codebox_left"><span id="l6code35"><a href="javascript:;" onclick="javascript:showCodeTxt('6code35'); return false;">View Code</a> PHP</span></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="635"><td width="1%" class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code" id="6code35"><pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">function</span> makebold<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$text</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
<span style="color: #ff0000">$text</span> <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">&quot;&amp;lt;b&amp;gt;&quot;</span><span style="color: #66cc66;">.</span><span style="color: #ff0000">$text</span><span style="color: #66cc66;">.</span><span style="color: #ff0000;">&quot;&amp;lt;/b&amp;gt;&quot;</span><span style="color: #66cc66;">;</span>
<span style="color: #b1b100;">return</span> <span style="color: #ff0000">$text</span><span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">&#125;</span>
<span style="color: #000066;">echo</span> makebold<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Php Tutorials by Wowebmaster.com&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p><strong>output</strong>:<br />
<code><br />
<strong>Php Tutorials by Wowebmaster.com</strong><br />
</code></p></blockquote>
<p>As seen above, <em>makebold()</em> function returned a value, which is a string, and we used that returning value by outputting (<em>echo</em>). Meaning, in the last line of code, <em>makebold</em> has a string value, that can be used like a variable.</p>
<p>One more example:</p>

<div class="wp_codebox_msgheader"><span class="codebox_right"><a href="javascript:;" onclick="toggle_collapse('636');">[<span id="636_symbol">-</span>]</a></span><span class="codebox_left"><span id="l6code36"><a href="javascript:;" onclick="javascript:showCodeTxt('6code36'); return false;">View Code</a> PHP</span></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="636"><td width="1%" class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code" id="6code36"><pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">function</span> calc <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$tshirt</span><span style="color: #66cc66;">,</span><span style="color: #ff0000">$number</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
<span style="color: #ff0000">$subtotal</span><span style="color: #66cc66;">=</span><span style="color: #ff0000">$tshirt</span> <span style="color: #66cc66;">*</span> <span style="color: #ff0000">$number</span><span style="color: #66cc66;">;</span> <span style="color: #808080; font-style: italic;">//total price is calculated</span>
<span style="color: #ff0000">$plustaxes</span><span style="color: #66cc66;">=</span> <span style="color: #ff0000">$subtotal</span> <span style="color: #66cc66;">*</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">110</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">100</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span> <span style="color: #808080; font-style: italic;">// plus 10% tax</span>
<span style="color: #b1b100;">return</span> <span style="color: #ff0000">$plustaxes</span><span style="color: #66cc66;">;</span> <span style="color: #808080; font-style: italic;">// returning the total price</span>
<span style="color: #66cc66;">&#125;</span>
<span style="color: #ff0000">$total</span><span style="color: #66cc66;">=</span><span style="color: #ff0000">$calc</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">4</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span> <span style="color: #808080; font-style: italic;">// $total has now the value of calc's return ($44)</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<div id="arrays"><strong>Arrays</strong></div>
<p>An array is a data structure that stores different values in one variable. Each array in php, has a key and a corresponding value.</p>
<blockquote><p>$array_name[key]=value</p></blockquote>
<p>Key and Values of the array can be a string or number.</p>
<blockquote><p><strong>A numerically indexed array</strong><br />
$names[0]=&#8221;john&#8221;;<br />
$names[1]=&#8221;elizabeth&#8221;;<br />
$names[2]=&#8221;ahmed&#8221;;<br />
$names[3]=&#8221;michael&#8221;;<br />
$names[4]=&#8221;carmen&#8221;;</p></blockquote>
<p>$names variable is an array, and has a length of 5. This is quiet useful for storing data by grouping.</p>
<blockquote><p><strong>Associative Arrays</strong><br />
$ages[&#8221;john&#8221;]=23;<br />
$ages[&#8221;elizabeth&#8221;]=24;<br />
$ages[&#8221;ahmed&#8221;]=21;<br />
$ages[&#8221;michael&#8221;]=23;<br />
$ages[&#8221;carmen&#8221;]=23;</p></blockquote>
<p>$ages variable is an array also, its keys are values (strings). Every key has associated with an age in this array. We will see usage examples after learning <em>loops</em> in php.</p>
<div id="wloops"><strong>While Loops</strong></div>
<p>While loops in php are continuous executing code blocks until a condition returns false.</p>

<div class="wp_codebox_msgheader"><span class="codebox_right"><a href="javascript:;" onclick="toggle_collapse('637');">[<span id="637_symbol">-</span>]</a></span><span class="codebox_left"><span id="l6code37"><a href="javascript:;" onclick="javascript:showCodeTxt('6code37'); return false;">View Code</a> PHP</span></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="637"><td width="1%" class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="6code37"><pre class="php"><span style="color: #b1b100;">while</span><span style="color: #66cc66;">&#40;</span> condition <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
expression<span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">&#125;</span>
somecode<span style="color: #66cc66;">;</span></pre></td></tr></table></div>

<p>Here how loop works:</p>
<ul>
<li>1: <em>Condition</em> inside <em>while</em> statement is checked</li>
<li>2: If the <em>condition</em> is true, <em>expression</em> is executed, if false jump out of <em>while</em> loop and execute <em>somecode</em>.</li>
<li>3: Jump back to state 1, check the <em>condition</em> again.</li>
</ul>

<div class="wp_codebox_msgheader"><span class="codebox_right"><a href="javascript:;" onclick="toggle_collapse('638');">[<span id="638_symbol">-</span>]</a></span><span class="codebox_left"><span id="l6code38"><a href="javascript:;" onclick="javascript:showCodeTxt('6code38'); return false;">View Code</a> PHP</span></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="638"><td width="1%" class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code" id="6code38"><pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #ff0000">$i</span> <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">;</span>
<span style="color: #b1b100;">while</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$i</span> <span style="color: #66cc66;">&amp;</span>lt<span style="color: #66cc66;">;=</span> <span style="color: #cc66cc;">10</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>   <span style="color: #808080; font-style: italic;">//smaller or equal</span>
<span style="color: #000066;">echo</span> <span style="color: #ff0000">$i</span><span style="color: #66cc66;">++;</span>  <span style="color: #808080; font-style: italic;">/* the printed value would be
$i before the increment
(post-increment) */</span>
<span style="color: #66cc66;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Above example, outputs numbers 1 to 10. Remember <em>$i++</em> means <em>$i=$i+1</em>. While $i is smaller than 10, $i is printed and then incremented. After incrementing, $i&lt;=10 condition is checked and the loop goes on until $i reaches 11.</p>

<div class="wp_codebox_msgheader"><span class="codebox_right"><a href="javascript:;" onclick="toggle_collapse('639');">[<span id="639_symbol">-</span>]</a></span><span class="codebox_left"><span id="l6code39"><a href="javascript:;" onclick="javascript:showCodeTxt('6code39'); return false;">View Code</a> PHP</span></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="639"><td width="1%" class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code" id="6code39"><pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #808080; font-style: italic;">// first, an array is filled</span>
<span style="color: #ff0000">$values</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;john&quot;</span><span style="color: #66cc66;">;</span>
<span style="color: #ff0000">$values</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;carmen&quot;</span><span style="color: #66cc66;">;</span>
<span style="color: #ff0000">$values</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;elizabeth&quot;</span><span style="color: #66cc66;">;</span>
<span style="color: #ff0000">$values</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;robert&quot;</span><span style="color: #66cc66;">;</span>
<span style="color: #ff0000">$values</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">4</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;michael&quot;</span><span style="color: #66cc66;">;</span>
<span style="color: #ff0000">$i</span><span style="color: #66cc66;">=</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">;</span> <span style="color: #808080; font-style: italic;">//starting value, key of array</span>
<span style="color: #b1b100;">while</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$i</span><span style="color: #66cc66;">&amp;</span>lt<span style="color: #66cc66;">;</span><span style="color: #cc66cc;">5</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>  <span style="color: #808080; font-style: italic;">/*our array is length of 5*/</span>
<span style="color: #000066;">echo</span> <span style="color: #ff0000">$values</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000">$i</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">.</span><span style="color: #ff0000;">&quot;&amp;lt;/br&amp;gt;&quot;</span><span style="color: #66cc66;">;</span>
<span style="color: #ff0000">$i</span><span style="color: #66cc66;">++;</span>  <span style="color: #808080; font-style: italic;">// incrementing key</span>
<span style="color: #66cc66;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p><strong>output:</strong></p>

<div class="wp_codebox_msgheader"><span class="codebox_right"><a href="javascript:;" onclick="toggle_collapse('640');">[<span id="640_symbol">-</span>]</a></span><span class="codebox_left"><span id="l6code40"><a href="javascript:;" onclick="javascript:showCodeTxt('6code40'); return false;">View Code</a> HTML</span></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="640"><td width="1%" class="line_numbers"><pre>1
</pre></td><td class="code" id="6code40"><pre>john&lt;/br&gt;carmen&lt;/br&gt;elizabeth&lt;/br&gt;robert&lt;/br&gt;michael&lt;/br&gt;</pre></td></tr></table></div>

<p>Above example, prints an array&#8217;s elements with while loop. We now explain the script line by line.</p>
<ul style="text-align:left">
<li>On the first line, we started to fill an array by defining its first element, $values[0]=&#8221;john&#8221;. The numeric id starts with a zero &#8220;0&#8243;.</li>
<li>On the second, third, fourth and fifth lines, elements of the array are assigned in order. Those 5 lines also can achieved by <em>array</em> function, which is $values=array(&#8221;john&#8221;,&#8221;carmen&#8221;,&#8221;elizabeth&#8221;,&#8221;robert&#8221;,&#8221;michael&#8221;);.</li>
<li>Our loop&#8217;s counter, also used as key of our array, is assigned a starting value, which maps to the first element of the array.</li>
<li>On the seventh line, while loop starts with condition ($i&lt;5). If condition is not met, the program jumps to the 10th line (out of while loop).</li>
<li>Array&#8217;s current element is output on the 8nd line. <em>$i</em> is used as key of our array <em>$values</em>.</li>
<li>$i is incremented to point to the next element of the array.</li>
<li>Program returns to the seventh line again.</li>
</ul>
<p>From the above explanation, you should understand that the loop is repeated 5 times, outputting the corresponding element of the array within each loop.</p>
<div id="floops"><strong>For Loops</strong></div>
<p><em>For loops</em> in php is similar to <em>while loops</em>. The difference is that you set up your own loop counter with your condition beside.</p>

<div class="wp_codebox_msgheader"><span class="codebox_right"><a href="javascript:;" onclick="toggle_collapse('641');">[<span id="641_symbol">-</span>]</a></span><span class="codebox_left"><span id="l6code41"><a href="javascript:;" onclick="javascript:showCodeTxt('6code41'); return false;">View Code</a> PHP</span></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="641"><td width="1%" class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code" id="6code41"><pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #808080; font-style: italic;">// first, an array is filled</span>
<span style="color: #ff0000">$values</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;john&quot;</span><span style="color: #66cc66;">;</span>
<span style="color: #ff0000">$values</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;carmen&quot;</span><span style="color: #66cc66;">;</span>
<span style="color: #ff0000">$values</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;elizabeth&quot;</span><span style="color: #66cc66;">;</span>
<span style="color: #ff0000">$values</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;robert&quot;</span><span style="color: #66cc66;">;</span>
<span style="color: #ff0000">$values</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">4</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;michael&quot;</span><span style="color: #66cc66;">;</span>
&nbsp;
<span style="color: #b1b100;">for</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$i</span><span style="color: #66cc66;">=</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">;</span> <span style="color: #ff0000">$i</span><span style="color: #66cc66;">&amp;</span>lt<span style="color: #66cc66;">;</span><span style="color: #cc66cc;">5</span><span style="color: #66cc66;">;</span> <span style="color: #ff0000">$i</span><span style="color: #66cc66;">++</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>  <span style="color: #808080; font-style: italic;">/*our array is length of 5*/</span>
<span style="color: #000066;">echo</span> <span style="color: #ff0000">$values</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000">$i</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">.</span><span style="color: #ff0000;">&quot;&amp;lt;/br&amp;gt;&quot;</span><span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>This code, actually, does the same thing that the example of <em>while loop</em> does. In <em>for loops</em>, your counter&#8217;s initial value must be set inside of the parentheses and after placing your condition, you must also add a counter behavior, it can be $i++; $i&#8211; or something similar. At first execution of <em>for loop</em>, the initial value is set, and then in every loop, the condition is checked and counter&#8217;s behavior is executed.</p>
<div id="formsusage">
<h4>HTML Forms &amp; Usage</h4>
</div>
<p>Forms in web sites, are used to gather information from the visitors of website. In the example below, we will demonstrate a very easy html form, that gets the required information for a user to subscribe a website&#8217;s sources.</p>

<div class="wp_codebox_msgheader"><span class="codebox_right"><a href="javascript:;" onclick="toggle_collapse('642');">[<span id="642_symbol">-</span>]</a></span><span class="codebox_left"><span id="l6code42"><a href="javascript:;" onclick="javascript:showCodeTxt('6code42'); return false;">View Code</a> HTML</span></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="642"><td width="1%" class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code" id="6code42"><pre>&lt;html&gt;
&lt;head&gt;
&lt;title&gt;HTML Form Example&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;form action=&quot;process.php&quot; method=&quot;post&quot; enctype=&quot;multipart/form-data&quot;&gt;
&lt;label&gt;Your Name: &lt;input name=&quot;name&quot; type=&quot;text&quot; /&gt;&lt;/label&gt;
&lt;label&gt;Your E-mail: &lt;input name=&quot;email&quot; type=&quot;text&quot; /&gt;&lt;/label&gt;
&lt;label&gt;Subscription Type: &lt;select name=&quot;type&quot;&gt;&lt;option&gt;Weekly&lt;/option&gt;&lt;option&gt;Monthly&lt;/option&gt;&lt;/select&gt; &lt;/label&gt;&lt;br/&gt;
&lt;input name=&quot;submit&quot; type=&quot;submit&quot; value=&quot;Submit&quot;&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></td></tr></table></div>

<p><b>Output:</b></p>
<blockquote>
<form action="process.php" method="post" enctype="multipart/form-data">
<label>Your Name:<br />
<input name="name" type="text" /></label><br />
<label>Your E-mail:<br />
<input name="email" type="text" /></label><br />
<label>Subscription Type:<br />
<select name="type"><option>Weekly</option><option>Monthly</option></select>
<p> </label><br/></p>
<input name="submit" type="submit" value="Submit">
</form>
</blockquote>
<p>The form, asks for user to type his/her name, e-mail and subscription type. When the user hits the submit button, the form sends all the information using <i>multipart/form-data</i> encryption, to <i>process.php</i> with POST method.</p>
<p><b>How to get the values sent by form?</b><br />
With the POST method, sent values can be accessed using the associative array, $_POST. Allt the information, is assigned to $_POST, names of the form tags as keys, and the value of the form tags as values of the array. Here is how it is done.</p>

<div class="wp_codebox_msgheader"><span class="codebox_right"><a href="javascript:;" onclick="toggle_collapse('643');">[<span id="643_symbol">-</span>]</a></span><span class="codebox_left"><span id="l6code43"><a href="javascript:;" onclick="javascript:showCodeTxt('6code43'); return false;">View Code</a> PHP</span></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="643"><td width="1%" class="line_numbe