<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Helpfolder</title>
	<atom:link href="http://helpfolder.com/feed" rel="self" type="application/rss+xml" />
	<link>http://helpfolder.com</link>
	<description></description>
	<lastBuildDate>Thu, 03 May 2012 02:17:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>How to Create a WordPress Plugin</title>
		<link>http://helpfolder.com/83/how-to-create-a-wordpress-plugin</link>
		<comments>http://helpfolder.com/83/how-to-create-a-wordpress-plugin#comments</comments>
		<pubDate>Thu, 03 May 2012 02:17:58 +0000</pubDate>
		<dc:creator>Mahesh</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://helpfolder.com/?p=83</guid>
		<description><![CDATA[WordPress plugins are easy to create even if you&#8217;re a newbie and barely know how to work with php. In this tutorial I am going to show you how you can create a simple php plugin, that shows wisdom quotes on the top of your blog. This is very basic tutorial for creating themes, what [...]]]></description>
			<content:encoded><![CDATA[<p>WordPress plugins are easy to create even if you&#8217;re a newbie and barely know how to work with php. In this tutorial I am going to show you how you can create a simple php plugin, that shows wisdom quotes on the top of your blog. This is very basic tutorial for creating themes, what shown in this theme can be achieved by other means, but we&#8217;re making this as a plugin for a simplicity in learning.<span id="more-83"></span></p>
<p><strong>Requirements: </strong></p>
<ul>
<li>WordPress 3.3</li>
<li>Text editor</li>
<li>php concepts</li>
</ul>
<p><strong>Random Text Code in Php</strong></p>
<p>We&#8217;re going to use a simple php script that lets you randomize the text snippets with each refresh.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"> <span style="color: #339933;">&lt;</span> ?
<span style="color: #000088;">$random_text</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Memory is the mother of all wisdom.&quot;</span><span style="color: #339933;">,</span>
                    <span style="color: #0000ff;">&quot;A short saying often contains much wisdom.&quot;</span><span style="color: #339933;">,</span>
                    <span style="color: #0000ff;">&quot;Without courage, wisdom bears no fruit.&quot;</span><span style="color: #339933;">,</span>
                    <span style="color: #0000ff;">&quot;Wisdom is the supreme part of happiness.&quot;</span><span style="color: #339933;">,</span>
                    <span style="color: #0000ff;">&quot;It is characteristic of wisdom not to do desperate things.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">srand</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$sizeof</span> <span style="color: #339933;">=</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$random_text</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$random</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">rand</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">%</span><span style="color: #000088;">$sizeof</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$random_text</span>[<span style="color: #006699; font-weight: bold;">$random</span>]&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>This code will be used in our plugin so that whenever we call the plugin function in our footer or header, it shows the random quotes. </p>
<p><strong>Preparation of Plugin</strong></p>
<p>Create a folder named &#8220;Wisdom Footer&#8221; and make a file named wisdom-footer.php in it. Now open that php file and add the following code into it.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span> ? php
&nbsp;
<span style="color: #666666; font-style: italic;">/*
Plugin Name: Wisdom Footer
Plugin URI: http://localhost/wordpress/
Description: Adds Wisdom Quotes in footer.
It is a plugin tutorial using latest plugin API of WP3.3+
Version: 0.1
Author: Mahesh
Author URI: http://helpfolder.com/
Disclaimer: Use at your own risk. No warranty expressed or implied is provided.
*/</span>
&nbsp;
? <span style="color: #339933;">&gt;</span></pre></div></div>

<p>Save the file. Now let&#8217;s write the function random_quotes so that we can use it later in our footer or index.php file. </p>
<p>Update the wisdom-footer.php with following code.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span> ? php
<span style="color: #666666; font-style: italic;">/*
Plugin Name: Wisdom Footer
Plugin URI: http://localhost/wordpress/
Description: Adds Wisdom Quotes in footer.
It is a plugin tutorial using latest plugin API of WP3.3+
Version: 0.1
Author: Mahesh
Author URI: http://helpfolder.com/
Disclaimer: Use at your own risk. No warranty expressed or implied is provided.
*/</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> random_quotes<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
<span style="color: #000088;">$random_text</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Memory is the mother of all wisdom.&quot;</span><span style="color: #339933;">,</span>
                    <span style="color: #0000ff;">&quot;A short saying often contains much wisdom.&quot;</span><span style="color: #339933;">,</span>
                    <span style="color: #0000ff;">&quot;Without courage, wisdom bears no fruit.&quot;</span><span style="color: #339933;">,</span>
                    <span style="color: #0000ff;">&quot;Wisdom is the supreme part of happiness.&quot;</span><span style="color: #339933;">,</span>
                    <span style="color: #0000ff;">&quot;It is characteristic of wisdom not to do desperate things.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">srand</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$sizeof</span> <span style="color: #339933;">=</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$random_text</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$random</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">rand</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">%</span><span style="color: #000088;">$sizeof</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$random_text</span>[<span style="color: #006699; font-weight: bold;">$random</span>]&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
? <span style="color: #339933;">&gt;</span></pre></div></div>

<p>Save the file and now find the theme&#8217;s index.php or footer.php. For a demo purpose i am using the index.php of twentyeleven theme. I have inserted the following code in the theme&#8217;s index.php file.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'random_quotes'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>
random_quotes<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span></pre></div></div>

<p>Make sure you use this code in the right place or it&#8217;ll not call the function &#8220;random_quotes&#8221;. I suggest placing this code at the top of the index.php so that you can test at the start of loadinng the theme.</p>
<p>Now pack your themes folder into wp-content/plugins directory and then go into the dashboaard and enabled the plugin. Now you&#8217;ll see the random wisdom quotes everytime you refresh the page.</p>
]]></content:encoded>
			<wfw:commentRss>http://helpfolder.com/83/how-to-create-a-wordpress-plugin/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Remove Xampp Splash Screen Redirection Error</title>
		<link>http://helpfolder.com/78/how-to-remove-xampp-splash-screen-redirection-error</link>
		<comments>http://helpfolder.com/78/how-to-remove-xampp-splash-screen-redirection-error#comments</comments>
		<pubDate>Wed, 02 May 2012 03:34:01 +0000</pubDate>
		<dc:creator>Mahesh</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://helpfolder.com/?p=78</guid>
		<description><![CDATA[You have installed xampp on your linux machine and now facing the error on splash screen. No matter how many times you click on the language links, it doesn&#8217;t redirect you to the index.php page. This error occurs because of the mismatch of the xampp folder permissions. The error here is because of the file [...]]]></description>
			<content:encoded><![CDATA[<p>You have installed xampp on your linux machine and now facing the error on splash screen. No matter how many times you click on the language links, it doesn&#8217;t redirect you to the index.php page. This error occurs because of the mismatch of the xampp folder permissions. <span id="more-78"></span></p>
<p>The error here is because of the file &#8220;<em>lang.tmp</em>&#8220;. You can find this file on &#8211; &#8220;<strong>/opt/lampp/htdocs/xampp/</strong>&#8221; folder. Now if you check the permission on this file, most likely it is set to the owner or the root of the linux machine. You have to reset the ownership to &#8220;nobody&#8221; so that apache can use this file to write on it.</p>
<p>In order to change the ownership of the file on linux machine. Use the following command on the terminal.</p>
<p><a href="http://helpfolder.com/wp-content/uploads/2012/05/terminal.png"><img class="aligncenter size-medium wp-image-79" title="terminal" src="http://helpfolder.com/wp-content/uploads/2012/05/terminal-300x186.png" alt="" width="300" height="186" /></a></p>
<p><code>sudo chown -R nobody /opt/lampp/xampp/lang.tmp</code></p>
<p>Make sure you are using the above command. Don&#8217;t use your own username instead of nobody because if you do then this error is likely to persist.</p>
<p><strong>Missing lang.tmp file</strong></p>
<p>If you have this file missing in the xampp installation in the folder specified previously then you have to create it manually. While creating this file do note that you have to reset the ownership back to the &#8220;nobody&#8221; so that apache can write on this file.</p>
<p>Hope this fix helps. If you still have this error on your linux machine, I suggest opening a thread on respective linux distro&#8217;s forums.</p>
]]></content:encoded>
			<wfw:commentRss>http://helpfolder.com/78/how-to-remove-xampp-splash-screen-redirection-error/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP MySQL Tutorial- Displaying Database Content in Webpage</title>
		<link>http://helpfolder.com/74/php-mysql-tutorial-displaying-database-content-in-webpage</link>
		<comments>http://helpfolder.com/74/php-mysql-tutorial-displaying-database-content-in-webpage#comments</comments>
		<pubDate>Sat, 25 Feb 2012 11:19:08 +0000</pubDate>
		<dc:creator>Mahesh</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://helpfolder.com/?p=74</guid>
		<description><![CDATA[In this tutorial, we&#8217;ll see how to display the contents of mysql table in your php webpage. In my previous tutorial of webserver setup, we checked out how to setup xampp or uniform server. Now you can use the phpmyadmin or sql console from these web server to perform database operations with your webpage. What [...]]]></description>
			<content:encoded><![CDATA[<p>In this tutorial, we&#8217;ll see how to display the contents of mysql table in your php webpage.  In my previous tutorial of <a href="http://helpfolder.com/60/codeigniter-setup-on-xampp-and-uniform-server">webserver setup</a>, we checked out how to setup xampp or uniform server. Now you can use the phpmyadmin or sql console from these web server to perform database operations with your webpage. <span id="more-74"></span></p>
<p><strong>What we&#8217;re going to do? </strong></p>
<ul>
<li>Establish connection with database. </li>
<li>Create an object (or reference) that holds the contents of database. </li>
<li>Perform action on database (like reading or writing). </li>
<li>Close the connection or Display the results.</li>
</ul>
<p>So now we&#8217;ve a goal to display the contents of the database with the help of php and mysql. Let&#8217;s first start with the database creation. </p>
<p>You can use phpmyadmin to create a database and populate the table with entries. I have created a database called contacts and inside it there is table called bizcard. There are three fields &#8211; No, Name, Surname. We&#8217;re going to make &#8220;No&#8221; a primary key. Right now we&#8217;re not worried about auto-increment and other stuff. So let&#8217;s just keep it as it is. </p>
<p>Now let&#8217;s write PHP code to fetch the content of our database &#8220;contacts&#8221;. Here is the code -</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"> <span style="color: #339933;">&lt;</span> ?php 
 <span style="color: #666666; font-style: italic;">// Connects to your Database </span>
 <span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;localhost&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;root&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;root&quot;</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
 <span style="color: #990000;">mysql_select_db</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;contacts&quot;</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
<span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT * FROM bizcard&quot;</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
  <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_assoc</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;No: &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'No'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;, Name:&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Name'</span><span style="color: #009900;">&#93;</span>
    <span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;, Surname:&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Surname'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;br/&gt;&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
 ? <span style="color: #339933;">&gt;</span></pre></div></div>

<p>First we&#8217;re connecting to the mysql server and for that we&#8217;re adding the credentials like &#8211; &#8220;name of the server&#8221; : localhost and username and password. My credentials and your web servers credentials will vary, so you have to check with xampp or uniform server on your desktop. In second part we&#8217;re connecting to the table if the previous connection to the database is successful. If there is any error in these two steps, mysql error will be thrown on webpage. </p>
<p> In third step, we&#8217;re creating an object or reference that fetches the content of our table &#8216;bizcard&#8217;. We&#8217;re now placing the cursor on each row and printing out the content of database. Based on the content inside the table, you&#8217;ll see the result in output. Make sure you don&#8217;t make mistakes here or else there will be mysql error thrown for your invalid syntax. </p>
]]></content:encoded>
			<wfw:commentRss>http://helpfolder.com/74/php-mysql-tutorial-displaying-database-content-in-webpage/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Exception Handling</title>
		<link>http://helpfolder.com/69/php-exception-handling</link>
		<comments>http://helpfolder.com/69/php-exception-handling#comments</comments>
		<pubDate>Sun, 19 Feb 2012 15:34:15 +0000</pubDate>
		<dc:creator>Mahesh</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://helpfolder.com/?p=69</guid>
		<description><![CDATA[PHP like any other programming language has an exception handling feature. You can write your code in a such way that it catches the most obvious exception depending on your programs logic. Exceptions allow you to manage errors much effectively and this is the reason you should consider using them in your program. In this [...]]]></description>
			<content:encoded><![CDATA[<p>PHP like any other programming language has an exception handling feature. You can write your code in a such way that it catches the most obvious exception depending on your programs logic. <span id="more-69"></span>Exceptions allow you to manage errors much effectively and this is the reason you should consider using them in your program. In this tutorial we&#8217;ll take a look at how exceptions in PHP work.</p>
<p>Before you check out the code, let&#8217;s take a look at the three keywords related to the exceptions.</p>
<ul>
<li><strong>Try</strong> &#8211; Inside the try function block we&#8217;re checking if a particular programming logic triggers an exception.</li>
<li><strong>Throw</strong> &#8211; If the program finds an exception in try block we throw an exception using throw keyword.</li>
<li><strong>Catch</strong> &#8211; This is the block where an object is created with exception information.</li>
</ul>
<p>Check the below code to see how an exception handling program works.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span> php try <span style="color: #009900;">&#123;</span>     <span style="color: #000088;">$checkvar</span><span style="color: #339933;">=</span> <span style="color: #0000ff;">'testing error'</span><span style="color: #339933;">;</span>     <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #000088;">$checkvar</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'ine is skipped by compiler as it moves directly in catch block after throwing an exception'</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
catch <span style="color: #009900;">&#40;</span>Exception <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Found an exception: '</span><span style="color: #339933;">,</span>
<span style="color: #000088;">$e</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>getMessage<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Exception program demo;
?&gt;</span></pre></div></div>

<p>In try block we&#8217;re creating a variable and throwing a new exception when compiler finds it. Any line after the throw keyword is not executed as the entire block is skipped to catch. So any code below the throw keyword is skipped. Inside catch block an exception is thrown and you get the error message printed. After this the last echo statement is printed on webpage.</p>
<p>Points to Remember:</p>
<ul>
<li>An exception can be caught or thrown with the help of php block.</li>
<li>There should be atleast one catch block for corresponding try block.</li>
<li>Exceptions can be thrown or rethrown within a catch block.</li>
</ul>
<p>You can use the exception handling while working with <a href="http://helpfolder.com/65/php-file-handling">php file handling</a> or network connection related programs. I hope this helps you to understand the exception handling in php. If you have any questions, suggestions related to this tutorial, feel free to comment. If the comments are expired on this post, feel free to use twitter to ask me.</p>
]]></content:encoded>
			<wfw:commentRss>http://helpfolder.com/69/php-exception-handling/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP File Handling</title>
		<link>http://helpfolder.com/65/php-file-handling</link>
		<comments>http://helpfolder.com/65/php-file-handling#comments</comments>
		<pubDate>Wed, 08 Feb 2012 21:36:21 +0000</pubDate>
		<dc:creator>Mahesh</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://helpfolder.com/?p=65</guid>
		<description><![CDATA[File handling is very important task that every php developer needs to learn. PHP offers you simple way to manipulate files. You can easily read, write, append or delete data in files. This comes in handy when you use PHP regex with your files. In file handling you&#8217;re basically doing following simple steps. Create a [...]]]></description>
			<content:encoded><![CDATA[<p>File handling is very important task that every php developer needs to learn. PHP offers you simple way to manipulate files. You can easily read, write, append or delete data in files. This comes in handy when you use<a href="http://helpfolder.com/56/php-regular-expressions"> PHP regex</a> with your files. <span id="more-65"></span></p>
<p>In file handling you&#8217;re basically doing following simple steps. </p>
<ul>
<li>Create a file.</li>
<li>Assign an object to open the file. </li>
<li>Read or write on the file.</li>
<li>Close the file.</li>
</ul>
<p>These four steps remain the same for every file management program in php or any other language. You just have to insert any other optional logic combining with these four steps. So let&#8217;s take a look at how to create a file using php program. </p>
<p><strong>The fopen() and fclose() function</strong></p>
<p>Let&#8217;s start with creating the file. In this example we&#8217;re going to assign file object to a variable. After that we&#8217;re going to open the file for writing with fopen() function and in this process if php fails to find the file, It&#8217;ll process the error message in the die() function. At the end we&#8217;re calling fclose() function to close the file.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span> php
<span style="color: #000088;">$dm_f</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;demophp.txt&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$dm_file</span><span style="color: #339933;">=</span><span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dm_f</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'w'</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;can't find file&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dm_file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
? <span style="color: #339933;">&gt;</span></pre></div></div>

<p>Note that we&#8217;re using the access mode &#8220;w&#8221; here which means we&#8217;re opening the file for write operations. You can use &#8220;r&#8221; mode if you wish to just read the file. In case of write only data is erased from the previous write and the new data is written on the file. You can use &#8220;a&#8221; append mode for appending the data to the file. </p>
<p><strong>Writing to File</strong></p>
<p>Check out the following code :</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span> ? php
<span style="color: #000088;">$dm_f</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;demophp.txt&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$dm_file</span><span style="color: #339933;">=</span><span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dm_f</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'w'</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;can't find file&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$dm_fw</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;this is new text<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">fwrite</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dm_file</span><span style="color: #339933;">,</span><span style="color: #000088;">$dm_fw</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$dm_fw</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;this is another one<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">fwrite</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dm_file</span><span style="color: #339933;">,</span><span style="color: #000088;">$dm_fw</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dm_file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
? <span style="color: #339933;">&gt;</span></pre></div></div>

<p>In Line 1: we&#8217;re creating a demophp.txt file and in Line 2: we&#8217;re creating file instance to write on our demophp.txt file. In Line 3: we&#8217;re creating a string that we&#8217;re going to add with the help of fwrite() function into our demophp file. Every time we created string, we used fwrite() function to pass it to the text file and at the end we closed the file using fclose() function. </p>
<p>You can also experiment with the access mode &#8216;a&#8217;. Why? In case of making log files or creating any file that adds the data on regular period will need both previous and current data and in that case append is useful. </p>
<p><strong>Reading a File</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span> ? php
<span style="color: #000088;">$dm_f</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;demophp.txt&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$dm_file</span><span style="color: #339933;">=</span><span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dm_f</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'r'</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;can't find file&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$dm_fr</span><span style="color: #339933;">=</span><span style="color: #990000;">fread</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dm_file</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">100</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dm_file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$dm_fr</span><span style="color: #339933;">;</span>
? <span style="color: #339933;">&gt;</span></pre></div></div>

<p>Reading a file follows the same format. You&#8217;re going to create a file then open that file with read access mode. By using fread() function you&#8217;re going to read the instance of file object by explicitly mentioning how many characters you want to read. In our example we&#8217;re using 100 as a fixed number. At the end we&#8217;re closing the file and then echoing the data read by variable.</p>
<p><strong>Deleting the File unlike function()</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>  ?php
<span style="color: #000088;">$dmf</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;thisfile.txt&quot;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">unlink</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dmf</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
? <span style="color: #339933;">&gt;</span></pre></div></div>

<p>Just be careful when you use unlink function as it deletes the content of the file from your server or disk. Deleting is very simple, you just have to pass the file object to the unlink() function. Just make sure you create another program to create the file and verify the existence before you use unlink() function. That way results are noticeable to you. </p>
<p>Hope this tutorial helps you to manipulate files using php. Feel free to let me know your feedback in comments. </p>
]]></content:encoded>
			<wfw:commentRss>http://helpfolder.com/65/php-file-handling/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Codeigniter Setup on Xampp and Uniform Server</title>
		<link>http://helpfolder.com/60/codeigniter-setup-on-xampp-and-uniform-server</link>
		<comments>http://helpfolder.com/60/codeigniter-setup-on-xampp-and-uniform-server#comments</comments>
		<pubDate>Sun, 05 Feb 2012 00:45:17 +0000</pubDate>
		<dc:creator>Mahesh</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://helpfolder.com/?p=60</guid>
		<description><![CDATA[Learn How to Setup Codeigniter with Xampp and Uniform Server. Codeigniter is one of the popular PHP framework that is suitable for many new php programmers. Codeigniter is lightweight and is relatively easy to understand php framework compared to cakephp and other frameworks. In this tutorial, we will setup codeigniter and get things running with [...]]]></description>
			<content:encoded><![CDATA[<p>Learn How to Setup Codeigniter with Xampp and Uniform Server. Codeigniter is one of the popular PHP framework that is suitable for many new php programmers. Codeigniter is lightweight and is relatively easy to understand php framework compared to cakephp and other frameworks. In this tutorial, we will setup codeigniter and get things running with XAMPP and Uniform server. <span id="more-60"></span>I am explaining codeigniter setup using both of these web servers just so that if anyone wants to use one of these will find it easy to setup. </p>
<p>We’re covering both webservers here so skip the steps of webserve which doesn’t apply to you. </p>
<p><strong>Xampp and Codeigniter Setup</strong>: </p>
<p>First thing we are going to do is setup Xampp for those who want to use codeigniter with xampp. So go ahead and download either portable version or developer version of <a href="http://www.apachefriends.org/en/xampp.html">xampp</a>. Install it in the directory (and drive) as per your choice. Once you copy all the files of xampp in directory, find the start.bat file to start the xampp server. You can also click on xampp control panel to manually start xampp services. </p>
<p>Second Download <a href="http://codeigniter.com">Codeigniter</a> and extract the files in “htdocs” folder of xampp. You can make the path something like this : <em>/htdocs/codeigniter or /htdocs/ci</em>. You can also rename the codeigniter folder as per your choice. </p>
<p>You can start the server and test the codeigniter setup at <em>http://localhost/codeigniter</em> or if you have renamed the codeigniter folder to something else, use that name. </p>
<p><strong>Uniform Server and Codeigniter Setup</strong>: </p>
<p><a href="http://www.uniformserver.com/">Unifrom server</a> is very easy to setup and is much better to manage sometimes compared to xampp. You can download uniform server and extrac it to the drive (and in turn directory) of your choice. Once extracted, navigate to the following directory: <em>\UniServer\udrive\www</em>. Inside the ‘www’ folder you have to extract the codeigniter. You can rename codeigniter to something simple if you wish that will definitely help while coding multiple codeigniter projects. </p>
<p>Start the server by going to following address: <em>http://localhost/CI</em>. </p>
<p>You will see the image as shown below in the screenshot.<br />
<img src="http://helpfolder.com/wp-content/uploads/2012/02/codeigniter_uniform_server-300x143.jpg" alt="" title="codeigniter_uniform_server" width="300" height="143" class="aligncenter size-medium wp-image-61" /></p>
<p>If you want to create your own welcome message for the application, you should edit the following file. </p>
<p><em>application/views/welcome_message.php</em></p>
<p>This completes our simple codeigniter setup tutorial. In next few tutorials, we will see how to setup dynamic websites and later in more advanced tutorials we will check out how to create simple blogs and forums. I hope this simple tutorial helps you to setup codeigniter on your development server. </p>
]]></content:encoded>
			<wfw:commentRss>http://helpfolder.com/60/codeigniter-setup-on-xampp-and-uniform-server/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Regular Expressions</title>
		<link>http://helpfolder.com/56/php-regular-expressions</link>
		<comments>http://helpfolder.com/56/php-regular-expressions#comments</comments>
		<pubDate>Thu, 26 Jan 2012 18:11:04 +0000</pubDate>
		<dc:creator>Mahesh</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://helpfolder.com/?p=56</guid>
		<description><![CDATA[Regular expressions are the patterns that allow you to processs text based on certain requirement. This in turn produces the sequence or pattern of text that is based on pattern-matching as per developers needs. You can do a lot of things using regular expressions. For example, you can filter our the text in uppercase or [...]]]></description>
			<content:encoded><![CDATA[<p>Regular expressions are the patterns that allow you to processs text based on certain requirement. This in turn produces the sequence or pattern of text that is based on pattern-matching as per developers needs. You can do a lot of things using regular expressions. <span id="more-56"></span>For example, you can filter our the text in uppercase or replace the word with something else, match the group of text and filter the content. There are plenty of other ways to use the regular expression as per your needs.</p>
<p>PHP allows you to use two types of regular expressions.</p>
<ul>
<li>POSIX Regular Expressions</li>
<li>PERL Style Regular Expressions</li>
</ul>
<p>I suggest you to follow the PERL Compatible Regular expressions as they&#8217;re widely used. There isn&#8217;t much difference between POSIX and PCRE but you&#8217;ve to learn separately to know them better.</p>
<p>There are ways to explain the valid and invalid patterns of regular expressions. I suggest you to use the examples to learn about these valid patterns. This is the reason I am not going to explain you every little expression, Instead you&#8217;ll learn from the examples posted here.</p>
<p>Let&#8217;s take a look at important perl compatible regular expression functions.</p>
<p><strong>preg_match()</strong> : This function performs a regular expression match. Check the following code to see it in action.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span> php
<span style="color: #000088;">$str</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;this is demo&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$str1</span><span style="color: #339933;">=</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/this/&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$str</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$str2</span><span style="color: #339933;">=</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/that/&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$str</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$str1</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;br/&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$str2</span><span style="color: #339933;">;</span>
? <span style="color: #339933;">&gt;</span></pre></div></div>

<p>Check the output and you&#8217;ll see that it shows 1 and 0. Here value 1 means we have found match and 0 means that there is no match. You can process much more complex data with the help of loops and reg operators.</p>
<p><strong>preg_replace()</strong>: This function performs regular expression search and replace operation. See the following code so that you get idea of how preg_replace() works.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span> php
<span style="color: #000088;">$data</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Here is some simple text&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$find</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;/is/&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$replace</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;is our&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$find</span><span style="color: #339933;">,</span><span style="color: #000088;">$replace</span><span style="color: #339933;">,</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
? <span style="color: #339933;">&gt;</span></pre></div></div>

<p>There are two more optional arguments that you can pass to the preg_replace() to count the replacements and also to restrict the number of replacements of text.</p>
<p><strong>preg_split()</strong>: This function takes your input and then split the input into multiple arrays. The value in array is dependent on your operator usage for spliting the text. PREG_SPLIT_NO_EMPTY argument ensures that no empty results are passed to the output of array. Check the following code on preg_split and see how we&#8217;re spliting the two statements that are separated with dot.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span> php
<span style="color: #000088;">$data</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Here is some simple text. Run the program&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$prodata</span><span style="color: #339933;">=</span><span style="color: #990000;">preg_split</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/\./'</span><span style="color: #339933;">,</span><span style="color: #000088;">$data</span><span style="color: #339933;">,-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>PREG_SPLIT_NO_EMPTY<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$prodata</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
? <span style="color: #339933;">&gt;</span></pre></div></div>

<p>Check the output and you&#8217;ll see that it splits the sentences in two arrays starting from [0].</p>
<p>This was just short introduction on regular expressions in php. You can read more about regular expressions in general from wikipedia. If you&#8217;re python programmer then do read <a href="http://onecore.net/regular-expressions-in-python.htm">python regular expressions</a> tutorial.</p>
<p>Feel free to let me know your suggestions and feedback on this tutorial. I would love to improve if there are any constructive criticisms in the comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://helpfolder.com/56/php-regular-expressions/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Solution to the Project Euler Problem 1</title>
		<link>http://helpfolder.com/48/php-solution-to-the-project-euler-problem-1</link>
		<comments>http://helpfolder.com/48/php-solution-to-the-project-euler-problem-1#comments</comments>
		<pubDate>Fri, 09 Dec 2011 20:30:18 +0000</pubDate>
		<dc:creator>Mahesh</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://helpfolder.com/?p=48</guid>
		<description><![CDATA[This is one of the easiest problem in the project euler archive. You can perform this problem in any language of your choice. As this site is specifically for web developers so i&#8217;m focusing on php for this post. You can change the code to get answer in C, C++ or any other language of [...]]]></description>
			<content:encoded><![CDATA[<p>This is one of the easiest problem in the project euler archive. You can perform this problem in any language of your choice. As this site is specifically for web developers so i&#8217;m focusing on php for this post. You can change the code to get answer in C, C++ or any other language of your choice. <span id="more-48"></span>Depending on your language, few changes will be there but that&#8217;s upto you to fix. As this tutorial deals with the PHP code, I can tell you for sure that this code works. </p>
<p>You can check the problem <a href="http://projecteuler.net/problem=1">here</a>. It says :</p>
<blockquote><p>If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.</p>
<p>Find the sum of all the multiples of 3 or 5 below 1000.</p></blockquote>
<p><strong>Thought Process</strong> &#8211; If you take a look at this problem you&#8217;ll observe that only numbers that are multiples of 3 and 5 are &#8211; 3, 5,6,9. You have to repeat this process for 1000 numbers in your program. Yes, you guessed it right we&#8217;re going to use loop in our program. We&#8217;re going to run a loop that counts upto 1000. We also need to check for the condition that checks the number is divisble by 3 and 5 and remainder is 0. In such case we&#8217;re going to use if condition inside our for loop to filter those numbers and it in our another variable that keep the sum.</p>
<p>You can see this in action in following code:</p>
<p><strong>Code</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$j</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$k</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$j</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span><span style="color: #000088;">$j</span><span style="color: #339933;">&lt;=</span><span style="color: #cc66cc;">1000</span><span style="color: #339933;">;</span><span style="color: #000088;">$j</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$j</span><span style="color: #339933;">%</span><span style="color:#800080;">3</span><span style="color: #339933;">==</span><span style="color: #cc66cc;">0</span> <span style="color: #339933;">||</span><span style="color: #000088;">$j</span><span style="color: #339933;">%</span><span style="color:#800080;">5</span><span style="color: #339933;">==</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
    <span style="color: #000088;">$k</span><span style="color: #339933;">+=</span><span style="color: #000088;">$j</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;The sum of Multiples of 3 and 5 is: &quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$k</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>This is very simple problem and I guess you should attempt it as much as possible before looking at this site for answer. If you manage to learn it in php, try to impement the logic in python or C# or C++. This will improve your language learning and logic too. </p>
]]></content:encoded>
			<wfw:commentRss>http://helpfolder.com/48/php-solution-to-the-project-euler-problem-1/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Loops</title>
		<link>http://helpfolder.com/45/php-loops</link>
		<comments>http://helpfolder.com/45/php-loops#comments</comments>
		<pubDate>Thu, 08 Dec 2011 08:19:26 +0000</pubDate>
		<dc:creator>Mahesh</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://helpfolder.com/?p=45</guid>
		<description><![CDATA[PHP like any other programming language makes use of loops to perform particular task repeatedly. You can use loops to perform tasks that are supposed to be executed if certain condition is met upto particular period. Like this there are many ways to use loops while programming with php. In this tutorial we&#8217;re going to [...]]]></description>
			<content:encoded><![CDATA[<p>PHP like any other programming language makes use of loops to perform particular task repeatedly. You can use loops to perform tasks that are supposed to be executed if certain condition is met upto particular period. <span id="more-45"></span>Like this there are many ways to use loops while programming with php. In this tutorial we&#8217;re going to take a look at ways with which we can use loops in php. </p>
<p>Loops always check for the particular condition before executing particular task. If the condition is true or false, it&#8217;ll generate the output for the loop. </p>
<p><strong>While Loop</strong></p>
<p>Let&#8217;s start learning with &#8216;while&#8217; loop first. Check the basic syntax of the while loop:</p>
<p><strong>Code</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span>condition<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>You&#8217;ve to place some condition in order to execute while loop. If your condition evalutes to true, the loop will execute or lese it&#8217;ll not.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">&lt;=</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$i</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;br/&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$i</span><span style="color: #339933;">++;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p><strong><br />
For Loop</strong></p>
<p>For loop allows you to have control over initiation, condition and increment in the same line. Like while loop it also processes a block of code until a statement becomes false. </p>
<p><strong>Syntax Code:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>condition<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>In this code our condition statement contains &#8211; <em>initiation, condition and increment</em>. You can skip increment if you want to use it inside the block of code. Either way with increment is fine with for loop. Check the modification in code made  for &#8211; &#8220;for loop&#8221;.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>$<span style="color: #339933;">=</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span><span style="color: #000088;">$i</span><span style="color: #339933;">&lt;=</span><span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span><span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$i</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;br/&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$i</span><span style="color: #339933;">++;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p><strong>FOREACH Loop</strong></p>
<p>A <em>foreach</em> loop is used when you&#8217;re dealing with arrays. It executes a block of code as long as loop uses all the values of arrays specified in the condition are used. Once those values are used then loop ends. So there is no need to explicitly add the increment for the arrays. </p>
<p><strong>Syntax</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$j</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>In this loop, we&#8217;re creating an array to be used <em>foreach</em> loop. This array specifies a particular set of values upto which the loop will execute.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$k</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$k</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;br/&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>As you can see in the output, this loop executes till all the values in array are used. Once used you can see that loop ends. </p>
<p>These three are the types of loops that you&#8217;re going to use while programming in php. Hope this tutorial helps to you and if you have any suggestion or feedback on these tutorials, feel free to let us know. </p>
]]></content:encoded>
			<wfw:commentRss>http://helpfolder.com/45/php-loops/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Redirect Users using PHP</title>
		<link>http://helpfolder.com/43/how-to-redirect-users-using-php</link>
		<comments>http://helpfolder.com/43/how-to-redirect-users-using-php#comments</comments>
		<pubDate>Wed, 07 Dec 2011 15:55:26 +0000</pubDate>
		<dc:creator>Mahesh</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://helpfolder.com/?p=43</guid>
		<description><![CDATA[There are many instances where redirection saves a lot of time. You can create a redirection to forwards users to a page which is translated for their locale. You can use redirection for affiliate link and you can also use redirection to avoid non-local folks to English version of your site. You can also redirect [...]]]></description>
			<content:encoded><![CDATA[<p>There are many instances where redirection saves a lot of time. You can create a redirection to forwards users to a page which is translated for their locale. You can use redirection for affiliate link and you can also use redirection to avoid non-local folks to English version of your site. <span id="more-43"></span>You can also redirect users from 404 page to homepage in order to help in SEO. There are many other uses of redirection script, it&#8217;s all upto you to use it in a way that gets your job done. </p>
<p>PHP redirects being a server side script works on all browsers and you don&#8217;t have to worry about browser standards. Redirection is quick and distraction free as you&#8217;re not wasting time by showing them some demo page in between the redirection. In this tutorial we&#8217;re assuming that you&#8217;re creating redirection on your 404 page. You can use the following code to redirect search engines and users to homepage. </p>
<p><strong>Code</strong>:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Location:http://yahoo.com'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>You can replace the yahoo with some other page of your site. You can also use specific 404 page or archive page which most of the websites use to redirect users. Archive page or sitemap pages are more useful as they let visitors make decision about where to visit next from the redirected page. </p>
<p><strong>Note:</strong> While running this php page make sure you&#8217;re not placing this code in < body > tag. Make this page purely php page without any other code in between and before or after the code. This should be the only code that needs to be executed in order for this example to work. If you&#8217;re using php designer 7 onwards then you may notice that redirection example may not work in the IDE. For some strange reasons it doesn&#8217;t work inside IDE. </p>
]]></content:encoded>
			<wfw:commentRss>http://helpfolder.com/43/how-to-redirect-users-using-php/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

