<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>PHP Tutorials</title>
	<atom:link href="http://phpindia.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://phpindia.wordpress.com</link>
	<description>Just another WordPress.com weblog</description>
	<lastBuildDate>Mon, 04 Feb 2008 06:58:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='phpindia.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>PHP Tutorials</title>
		<link>http://phpindia.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://phpindia.wordpress.com/osd.xml" title="PHP Tutorials" />
	<atom:link rel='hub' href='http://phpindia.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Interview Questions</title>
		<link>http://phpindia.wordpress.com/2008/02/04/interview-questions/</link>
		<comments>http://phpindia.wordpress.com/2008/02/04/interview-questions/#comments</comments>
		<pubDate>Mon, 04 Feb 2008 06:58:21 +0000</pubDate>
		<dc:creator>pankajkapil</dc:creator>
				<category><![CDATA[Interview Questions]]></category>

		<guid isPermaLink="false">http://phpindia.wordpress.com/?p=31</guid>
		<description><![CDATA[What&#8217;s PHP The PHP Hypertext Preprocessor is a programming language that allows web developers to create dynamic content that interacts with databases. PHP is basically used for developing web based software applications. What Is a Session? A session is a logical object created by the PHP engine to allow you to preserve data across subsequent [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=phpindia.wordpress.com&amp;blog=2162490&amp;post=31&amp;subd=phpindia&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p> <b>What&#8217;s PHP </b></p>
<p>The PHP Hypertext Preprocessor is a programming language that allows web developers to create dynamic content that interacts with databases. PHP is basically used for developing web based software applications.</p>
<p><b> What Is a Session? </b></p>
<p>A session is a logical object created by the PHP engine to allow you  to preserve data across subsequent HTTP requests.</p>
<p>There is only one session object available to your PHP scripts at any time.  Data saved to the session by a script can be retrieved by the same script  or another script when requested from the same visitor.</p>
<p>Sessions are commonly used to store temporary data to allow multiple PHP pages to offer a complete functional transaction for the same visitor.</p>
<p><b> What is meant by PEAR in php? </b></p>
<p>Answer1:<br />
PEAR is the next revolution in PHP. This repository is bringing higher level programming to PHP. PEAR is a framework and distribution system for reusable PHP components. It eases installation by bringing an automated wizard, and packing the strength and experience of PHP users into a nicely organised OOP library. PEAR also provides a command-line interface that can be used to automatically install &#8220;packages&#8221;</p>
<p>Answer2:<br />
PEAR is short for &#8220;PHP Extension and Application Repository&#8221; and is pronounced just like the fruit. The purpose of PEAR is to provide:<br />
A structured library of open-sourced code for PHP users<br />
A system for code distribution and package maintenance<br />
A standard style for code written in PHP<br />
The PHP Foundation Classes (PFC),<br />
The PHP Extension Community Library (PECL),<br />
A web site, mailing lists and download mirrors to support the PHP/PEAR community<br />
PEAR is a community-driven project with the PEAR Group as the governing body. The project has been founded by Stig S. Bakken in 1999 and quite a lot of people have joined the project since then.</p>
<p><b> How can we know the number of days between two given dates using PHP? </b></p>
<p>Simple arithmetic:</p>
<p>$date1 = date(&#8216;Y-m-d&#8217;);<br />
$date2 = &#8217;2006-07-01&#8242;;<br />
$days = (strtotime() &#8211; strtotime()) / (60 * 60 * 24);<br />
echo &#8220;Number of days since &#8217;2006-07-01&#8242;: $days&#8221;;</p>
<p><b> How can we repair a MySQL table? </b></p>
<p>The syntex for repairing a mysql table is:</p>
<p>REPAIR TABLE tablename<br />
REPAIR TABLE tablename QUICK<br />
REPAIR TABLE tablename EXTENDED</p>
<p>This command will repair the table specified.<br />
If QUICK is given, MySQL will do a repair of only the index tree.<br />
If EXTENDED is given, it will create index row by row.</p>
<p><b>What is the difference between $message and $$message? </b></p>
<p>Anwser 1:<br />
$message is a simple variable whereas $$message is a reference variable. Example:<br />
$user = &#8216;bob&#8217;</p>
<p>is equivalent to</p>
<p>$holder = &#8216;user&#8217;;<br />
$$holder = &#8216;bob&#8217;;</p>
<p>Anwser 2:<br />
They are both variables. But $message is a variable with a fixed name.  $$message is a variable who&#8217;s name is stored in $message. For example,  if $message contains &#8220;var&#8221;, $$message is the same as $var.</p>
<p><b> What Is a Persistent Cookie? </b></p>
<p>A persistent cookie is a cookie which is stored in a cookie file permanently on the browser&#8217;s computer. By default, cookies are created as temporary cookies which stored only in the browser&#8217;s memory. When the browser is closed, temporary cookies will be erased. You should decide when to use temporary cookies and when to use persistent cookies based on their differences:</p>
<ul>
<li>Temporary cookies can not be used for tracking long-term information.</li>
<li>Persistent cookies can be used for tracking long-term information.</li>
<li>Temporary cookies are safer because no programs other than the browser can access them.</li>
<li></li>
<li>Persistent cookies are less secure because users can open cookie files see the cookie values.</li>
</ul>
<p><b> How do you define a constant?  </b></p>
<p>Via define() directive, like define (&#8220;MYCONSTANT&#8221;, 100);</p>
<p><b>How To Write the FORM Tag Correctly for Uploading Files? </b></p>
<p>When users clicks the submit button, files specified in the &lt;INPUT TYPE=FILE&#8230;&gt;  will be transferred from the browser to the Web server. This transferring (uploading) process  is controlled by a properly written &lt;FORM&#8230;&gt; tag as:</p>
<pre>  &lt;FORM ACTION=receiving.php METHOD=post ENCTYPE=multipart/form-data&gt;</pre>
<p>Note that you must specify METHOD as &#8220;post&#8221; and ENCTYPE as &#8220;multipart/form-data&#8221; in order for the uploading process to work. The following PHP code, called logo_upload.php, shows you a complete FORM tag for file uploading:</p>
<pre>&lt;?php
  print("&lt;html&gt;&lt;form action=processing_uploaded_files.php"
    ." method=post enctype=multipart/form-data&gt;\n");
  print("Please submit an image file a Web site logo for"
    ." fyicenter.com:&lt;br&gt;\n");
  print("&lt;input type=file name=fyicenter_logo&gt;&lt;br&gt;\n");
  print("&lt;input type=submit&gt;\n");
  print("&lt;/form&gt;&lt;/html&gt;\n");
?&gt;</pre>
<pre></pre>
<p><b> What are the differences between require and include, include_once? </b></p>
<p>Anwser 1:<br />
require_once() and include_once() are both the functions to include and evaluate the specified file only once. If the specified file is included previous to the present call occurrence, it will not be done again.</p>
<p>But require() and include() will do it as many times they are asked to do.</p>
<p>Anwser 2:<br />
The include_once() statement includes and evaluates the specified file during the execution of the script. This is a behavior similar to the include() statement, with the only difference being that if the code from a file has already been included, it will not be included again. The major difference between include() and require() is that in failure include() produces a warning message whereas require() produces a fatal errors.</p>
<p>Anwser 3:<br />
All three are used to an include file into the current page.<br />
If the file is not present, require(), calls a fatal error, while in include() does not.<br />
The include_once() statement includes and evaluates the specified file during the execution of the script. This is a behavior similar to the include() statement, with the only difference being that if the code from a file has already been included, it will not be included again. It des not call a fatal error if file not exists. require_once() does the same as include_once(), but it calls a fatal error if file not exists.</p>
<p>Anwser 4:<br />
File will not be included more than once. If we want to include a file once only and further calling of the file will be ignored then we have to use the PHP function include_once().  This will prevent problems with function redefinitions, variable value reassignments, etc.</p>
<pre></pre>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/phpindia.wordpress.com/31/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/phpindia.wordpress.com/31/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/phpindia.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/phpindia.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/phpindia.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/phpindia.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/phpindia.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/phpindia.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/phpindia.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/phpindia.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/phpindia.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/phpindia.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/phpindia.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/phpindia.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/phpindia.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/phpindia.wordpress.com/31/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=phpindia.wordpress.com&amp;blog=2162490&amp;post=31&amp;subd=phpindia&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://phpindia.wordpress.com/2008/02/04/interview-questions/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ec501295341c1654cd0613192abf608b?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pankajkapil</media:title>
		</media:content>
	</item>
		<item>
		<title>PHP Sessions</title>
		<link>http://phpindia.wordpress.com/2008/01/15/php-sessions/</link>
		<comments>http://phpindia.wordpress.com/2008/01/15/php-sessions/#comments</comments>
		<pubDate>Tue, 15 Jan 2008 07:01:41 +0000</pubDate>
		<dc:creator>pankajkapil</dc:creator>
				<category><![CDATA[PHP Sessions]]></category>

		<guid isPermaLink="false">http://phpindia.wordpress.com/2008/01/15/php-sessions/</guid>
		<description><![CDATA[A PHP session variable is used to store information about, or change settings for a user session. Session variables hold information about one single user, and are available to all pages in one application. PHP Session Variables When you are working with an application, you open it, do some changes and then you close it. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=phpindia.wordpress.com&amp;blog=2162490&amp;post=30&amp;subd=phpindia&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p class="intro">A PHP session variable is used to store information about, or  change settings for a user session. Session variables hold information about one  single user, and are available to all pages in one application.</p>
<hr />
<h2>PHP Session Variables</h2>
<p>When you are working with an application, you open it, do some changes and  then you close it. This is much like a Session. The computer knows who you are.  It knows when you start the application and when you end. But on the internet  there is one problem: the web server does not know who you are and what you do  because the HTTP address doesn&#8217;t maintain state.</p>
<p>A PHP session solves this problem by allowing you to store user information  on the server for later use (i.e. username, shopping items, etc). However, session information is temporary and  will be deleted after  the user has left the website. If you need a permanent storage you may want to store the data in a database.</p>
<p>Sessions work by creating a unique id (UID) for each  visitor and store variables based on this UID. The UID is either stored in a  cookie or is propagated in the URL.</p>
<hr />
<h2>Starting a PHP Session</h2>
<p>Before you can store user information in your PHP session, you must  first start up the session.</p>
<p><b>Note:</b> The session_start() function must appear BEFORE the &lt;html&gt; tag:</p>
<table class="ex" id="table6" border="1" cellspacing="0" width="100%">
<tr>
<td>
<pre>&lt;?php session_start(); ?&gt;</pre>
<pre>&lt;html&gt;
&lt;body&gt;</pre>
<pre>&lt;/body&gt;
&lt;/html&gt;</pre>
</td>
</tr>
</table>
<p>The code above will register the user&#8217;s session with the server, allow you to  start saving user information, and assign a UID  for that user&#8217;s session.</p>
<hr />
<h2>Storing a Session Variable</h2>
<p>The correct way to store and retrieve session variables is to use the  PHP $_SESSION variable:</p>
<table class="ex" id="table7" border="1" cellspacing="0" width="100%">
<tr>
<td>
<pre>&lt;?php
session_start();
// store session data
$_SESSION['views']=1;
?&gt;</pre>
<pre>&lt;html&gt;
&lt;body&gt;</pre>
<pre>&lt;?php
//retrieve session data
echo "Pageviews=". $_SESSION['views'];
?&gt;</pre>
<pre>&lt;/body&gt;
&lt;/html&gt;</pre>
</td>
</tr>
</table>
<p>Output:</p>
<table class="ex" id="table8" border="1" cellspacing="0" width="100%">
<tr>
<td>
<pre>Pageviews=1</pre>
</td>
</tr>
</table>
<p>In the example below, we create a simple page-views counter. The isset()  function checks if the &#8220;views&#8221; variable has already been set. If &#8220;views&#8221; has  been set, we  can increment our counter. If &#8220;views&#8221; doesn&#8217;t exist, we create a &#8220;views&#8221;  variable,  and set it to 1:</p>
<table class="ex" id="table9" border="1" cellspacing="0" width="100%">
<tr>
<td>
<pre>&lt;?php

session_start();</pre>
<pre>if(isset($_SESSION['views']))
  $_SESSION['views']=$_SESSION['views']+1;

else
  $_SESSION['views']=1;
echo "Views=". $_SESSION['views'];
?&gt;</pre>
</td>
</tr>
</table>
<hr />
<h2>Destroying a Session</h2>
<p>If you wish to delete some session data, you can use the unset() or the  session_destroy() function.</p>
<p>The unset() function is used to free the specified session variable:</p>
<table class="ex" id="table10" border="1" cellspacing="0" width="100%">
<tr>
<td>
<pre>&lt;?php
unset($_SESSION['views']);
?&gt;</pre>
</td>
</tr>
</table>
<p>You can also completely destroy the session by calling the session_destroy() function:</p>
<table class="ex" id="table11" border="1" cellspacing="0" width="100%">
<tr>
<td>
<pre>&lt;?php
session_destroy();
?&gt;</pre>
</td>
</tr>
</table>
<p><b>Note:</b> session_destroy() will reset your session and you will lose all  your stored session data.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/phpindia.wordpress.com/30/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/phpindia.wordpress.com/30/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/phpindia.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/phpindia.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/phpindia.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/phpindia.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/phpindia.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/phpindia.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/phpindia.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/phpindia.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/phpindia.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/phpindia.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/phpindia.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/phpindia.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/phpindia.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/phpindia.wordpress.com/30/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=phpindia.wordpress.com&amp;blog=2162490&amp;post=30&amp;subd=phpindia&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://phpindia.wordpress.com/2008/01/15/php-sessions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ec501295341c1654cd0613192abf608b?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pankajkapil</media:title>
		</media:content>
	</item>
		<item>
		<title>PHP Cookies</title>
		<link>http://phpindia.wordpress.com/2008/01/15/php-cookies/</link>
		<comments>http://phpindia.wordpress.com/2008/01/15/php-cookies/#comments</comments>
		<pubDate>Tue, 15 Jan 2008 06:49:43 +0000</pubDate>
		<dc:creator>pankajkapil</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://phpindia.wordpress.com/2008/01/15/php-cookies/</guid>
		<description><![CDATA[A cookie is often used to identify a user. What is a Cookie? A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user&#8217;s computer. Each time the same computer requests a page with a browser, it will send the cookie too. With PHP, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=phpindia.wordpress.com&amp;blog=2162490&amp;post=29&amp;subd=phpindia&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p class="intro">A cookie is often used to identify a user.</p>
<hr />
<h2>What is a Cookie?</h2>
<p>A cookie is often used to identify a user. A cookie is a small file that the  server embeds on the user&#8217;s computer. Each time the same computer requests a  page with a browser, it will send the cookie too. With PHP, you can both create  and retrieve cookie values.</p>
<hr />
<h2>How to Create a Cookie?</h2>
<p>The setcookie() function is used to set a cookie.</p>
<p><b>Note:</b> The setcookie() function must appear BEFORE the &lt;html&gt; tag.</p>
<h3>Syntax</h3>
<table class="ex" border="1" cellspacing="0" width="100%">
<tr>
<td>
<pre>setcookie(name, value, expire, path, domain);</pre>
</td>
</tr>
</table>
<h3>Example</h3>
<p>In the example below, we will create a cookie named &#8220;user&#8221; and assign the  value &#8220;Alex Porter&#8221; to it. We also specify that the cookie should expire after  one hour:</p>
<table class="ex" border="1" cellspacing="0" width="100%">
<tr>
<td>
<pre>&lt;?php
setcookie("user", "Alex Porter", time()+3600);
?&gt;</pre>
<pre>&lt;html&gt;
&lt;body&gt;</pre>
<pre>&lt;/body&gt;
&lt;/html&gt;</pre>
</td>
</tr>
</table>
<p><b>Note: </b>The value of the cookie is automatically URLencoded when  sending the cookie, and automatically decoded when received (to prevent  URLencoding, use setrawcookie() instead).</p>
<hr />
<h2>How to Retrieve a Cookie Value?</h2>
<p>The PHP $_COOKIE variable is used to  retrieve a cookie value.</p>
<p>In the example below, we retrieve the value of the cookie named &#8220;user&#8221; and  display it on a page:</p>
<table class="ex" id="table3" border="1" cellspacing="0" width="100%">
<tr>
<td>
<pre>&lt;?php
// Print a cookie
echo $_COOKIE["user"];</pre>
<pre>// A way to view all cookies
print_r($_COOKIE);
?&gt;</pre>
</td>
</tr>
</table>
<p>In the following example we use the isset() function to find out if a cookie  has been set:</p>
<table class="ex" id="table4" border="1" cellspacing="0" width="100%">
<tr>
<td>
<pre>&lt;html&gt;
&lt;body&gt;</pre>
<pre>&lt;?php
if (isset($_COOKIE["user"]))
  echo "Welcome " . $_COOKIE["user"] . "!&lt;br /&gt;";
else
  echo "Welcome guest!&lt;br /&gt;";
?&gt;</pre>
<pre>&lt;/body&gt;
&lt;/html&gt;</pre>
</td>
</tr>
</table>
<hr />
<h2>How to Delete a Cookie?</h2>
<p>When deleting a cookie you should assure that the expiration date is in the  past.</p>
<p>Delete example:</p>
<table class="ex" id="table5" border="1" cellspacing="0" width="100%">
<tr>
<td>
<pre>&lt;?php
// set the expiration date to one hour ago
setcookie("user", "", time()-3600);
?&gt;</pre>
</td>
</tr>
</table>
<hr />
<h2>What if a Browser Does NOT Support Cookies?</h2>
<p>If your application deals with browsers that do not support cookies, you will  have to use other methods to pass information from one page to another in your  application. One method is to pass the data through forms (forms and user input are described  earlier in this tutorial).</p>
<p>The form below passes the user input to &#8220;welcome.php&#8221; when the user clicks on  the &#8220;Submit&#8221; button:</p>
<table class="ex" id="table1" border="1" cellspacing="0" width="100%">
<tr>
<td>
<pre>&lt;html&gt;
&lt;body&gt;</pre>
<pre>&lt;form action="welcome.php" method="post"&gt;
Name: &lt;input type="text" name="name" /&gt;
Age: &lt;input type="text" name="age" /&gt;
&lt;input type="submit" /&gt;
&lt;/form&gt;</pre>
<pre>&lt;/body&gt;
&lt;/html&gt;</pre>
</td>
</tr>
</table>
<p>Retrieve the values in the &#8220;welcome.php&#8221; file like this:</p>
<table class="ex" id="table2" border="1" cellspacing="0" width="100%">
<tr>
<td>
<pre>&lt;html&gt;
&lt;body&gt;</pre>
<pre>Welcome &lt;?php echo $_POST["name"]; ?&gt;.&lt;br /&gt;
You are &lt;?php echo $_POST["age"]; ?&gt; years old.</pre>
<pre>&lt;/body&gt;
&lt;/html&gt;</pre>
</td>
</tr>
</table>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/phpindia.wordpress.com/29/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/phpindia.wordpress.com/29/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/phpindia.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/phpindia.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/phpindia.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/phpindia.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/phpindia.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/phpindia.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/phpindia.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/phpindia.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/phpindia.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/phpindia.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/phpindia.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/phpindia.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/phpindia.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/phpindia.wordpress.com/29/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=phpindia.wordpress.com&amp;blog=2162490&amp;post=29&amp;subd=phpindia&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://phpindia.wordpress.com/2008/01/15/php-cookies/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ec501295341c1654cd0613192abf608b?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pankajkapil</media:title>
		</media:content>
	</item>
		<item>
		<title>PHP File Upload</title>
		<link>http://phpindia.wordpress.com/2008/01/15/php-file-upload/</link>
		<comments>http://phpindia.wordpress.com/2008/01/15/php-file-upload/#comments</comments>
		<pubDate>Tue, 15 Jan 2008 06:31:06 +0000</pubDate>
		<dc:creator>pankajkapil</dc:creator>
				<category><![CDATA[PHP File Upload]]></category>

		<guid isPermaLink="false">http://phpindia.wordpress.com/2008/01/15/php-file-upload/</guid>
		<description><![CDATA[With PHP, it is possible to upload files to the server. Create an Upload-File Form To allow users to upload files from a form can be very useful. Look at the following HTML form for uploading files: &#60;html&#62; &#60;body&#62; &#60;form action="upload_file.php" method="post" enctype="multipart/form-data"&#62; &#60;label for="file"&#62;Filename:&#60;/label&#62; &#60;input type="file" name="file" id="file" /&#62; &#60;br /&#62; &#60;input type="submit" name="submit" [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=phpindia.wordpress.com&amp;blog=2162490&amp;post=28&amp;subd=phpindia&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p class="intro">With PHP, it is possible to upload files to the server.</p>
<hr />
<h2>Create an Upload-File Form</h2>
<p>To allow users to upload files from a form can be very useful.</p>
<p>Look at the following HTML form for uploading files:</p>
<table class="ex" border="1" cellspacing="0" width="100%">
<tr>
<td>
<pre>&lt;html&gt;
&lt;body&gt;</pre>
<pre>&lt;form action="upload_file.php" method="post"
enctype="multipart/form-data"&gt;
&lt;label for="file"&gt;Filename:&lt;/label&gt;
&lt;input type="file" name="file" id="file" /&gt;
&lt;br /&gt;
&lt;input type="submit" name="submit" value="Submit" /&gt;
&lt;/form&gt;</pre>
<pre>&lt;/body&gt;
&lt;/html&gt;</pre>
</td>
</tr>
</table>
<p>Notice the following about the HTML form above:</p>
<ul>
<li>The enctype attribute of the &lt;form&gt; tag specifies which content-type to use when  	submitting the form. &#8220;multipart/form-data&#8221; is used when a form requires  	binary data, like the contents of a file, to be uploaded</li>
<li>The type=&#8221;file&#8221; attribute of the &lt;input&gt; tag specifies that the input should  	be processed as a file. For example, when viewed in a browser, there will be  	a browse-button next to the input field</li>
</ul>
<p><b>Note:</b> Allowing users to upload files is a big security risk. Only permit  trusted users  to perform file uploads.</p>
<hr />
<h2>Create The Upload Script</h2>
<p>The &#8220;upload_file.php&#8221; file contains the code for uploading a file:</p>
<table class="ex" border="1" cellspacing="0" width="100%">
<tr>
<td>
<pre>&lt;?php
if ($_FILES["file"]["error"] &gt; 0)
  {
  echo "Error: " . $_FILES["file"]["error"] . "&lt;br /&gt;";
  }
else
  {
  echo "Upload: " . $_FILES["file"]["name"] . "&lt;br /&gt;";
  echo "Type: " . $_FILES["file"]["type"] . "&lt;br /&gt;";
  echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb&lt;br /&gt;";
  echo "Stored in: " . $_FILES["file"]["tmp_name"];
  }
?&gt;</pre>
</td>
</tr>
</table>
<p>By using the global PHP $_FILES array you can upload files from a client computer to  the remote server.</p>
<p>The first parameter is the form&#8217;s input name and the second index can be  either &#8220;name&#8221;, &#8220;type&#8221;, &#8220;size&#8221;, &#8220;tmp_name&#8221; or &#8220;error&#8221;. Like this:</p>
<ul>
<li>$_FILES["file"]["name"] &#8211; the name of the uploaded file</li>
<li>$_FILES["file"]["type"] &#8211; the type of the uploaded file</li>
<li>$_FILES["file"]["size"] &#8211; the size in bytes of the uploaded file</li>
<li>$_FILES["file"]["tmp_name"] &#8211; the name of the temporary copy of  	the file stored on the server</li>
<li>$_FILES["file"]["error"] &#8211; the error code resulting from the file  	upload</li>
</ul>
<p>This is a very simple way of uploading files. For security reasons, you  should add  restrictions on what the user is allowed to upload.</p>
<hr />
<h2>Restrictions on Upload</h2>
<p>In this script we add some restrictions to the file upload. The user may only upload  .gif or .jpeg files and the file size must be under 20 kb:</p>
<table class="ex" border="1" cellspacing="0" width="100%">
<tr>
<td>
<pre>&lt;?php</pre>
<pre>if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&amp;&amp; ($_FILES["file"]["size"] &lt; 20000))
  {
  if ($_FILES["file"]["error"] &gt; 0)
    {
    echo "Error: " . $_FILES["file"]["error"] . "&lt;br /&gt;";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "&lt;br /&gt;";
    echo "Type: " . $_FILES["file"]["type"] . "&lt;br /&gt;";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb&lt;br /&gt;";
    echo "Stored in: " . $_FILES["file"]["tmp_name"];
    }
  }
else
  {
  echo "Invalid file";
  }</pre>
<pre>?&gt;</pre>
</td>
</tr>
</table>
<p><b>Note:</b> For IE to recognize jpg files the type must be pjpeg, for  FireFox it must be jpeg.</p>
<hr />
<h2>Saving the Uploaded File</h2>
<p>The examples above create a temporary copy of the uploaded files in the PHP  temp folder on the server.</p>
<p>The temporary copied files disappears when the script ends. To store the  uploaded file we need to copy it to a different location:</p>
<table class="ex" border="1" cellspacing="0" width="100%">
<tr>
<td>
<pre>&lt;?php
if (($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg")
&amp;&amp; ($_FILES["file"]["size"] &lt; 20000))
  {
  if ($_FILES["file"]["error"] &gt; 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "&lt;br /&gt;";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "&lt;br /&gt;";
    echo "Type: " . $_FILES["file"]["type"] . "&lt;br /&gt;";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb&lt;br /&gt;";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "&lt;br /&gt;";</pre>
<pre>    if (file_exists("upload/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "upload/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
      }
    }
  }
else
  {
  echo "Invalid file";
  }
?&gt;</pre>
</td>
</tr>
</table>
<p>The script above checks if the file already exists, if it does not, it copies the file to the specified folder.</p>
<p><b>Note:</b> This example saves the file to a new folder called &#8220;upload&#8221;</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/phpindia.wordpress.com/28/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/phpindia.wordpress.com/28/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/phpindia.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/phpindia.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/phpindia.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/phpindia.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/phpindia.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/phpindia.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/phpindia.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/phpindia.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/phpindia.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/phpindia.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/phpindia.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/phpindia.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/phpindia.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/phpindia.wordpress.com/28/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=phpindia.wordpress.com&amp;blog=2162490&amp;post=28&amp;subd=phpindia&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://phpindia.wordpress.com/2008/01/15/php-file-upload/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ec501295341c1654cd0613192abf608b?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pankajkapil</media:title>
		</media:content>
	</item>
		<item>
		<title>PHP File Handling</title>
		<link>http://phpindia.wordpress.com/2008/01/15/php-file-handling/</link>
		<comments>http://phpindia.wordpress.com/2008/01/15/php-file-handling/#comments</comments>
		<pubDate>Tue, 15 Jan 2008 06:09:08 +0000</pubDate>
		<dc:creator>pankajkapil</dc:creator>
				<category><![CDATA[PHP File Handling]]></category>

		<guid isPermaLink="false">http://phpindia.wordpress.com/2008/01/15/php-file-handling/</guid>
		<description><![CDATA[The fopen() function is used to open files in PHP. Opening a File The fopen() function is used to open files in PHP. The first parameter of this function contains the name of the file to be opened and the second parameter specifies in which mode the file should be opened: &#60;html&#62; &#60;body&#62; &#60;?php $file=fopen("welcome.txt","r"); [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=phpindia.wordpress.com&amp;blog=2162490&amp;post=27&amp;subd=phpindia&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p class="intro">The fopen() function is used to open files in PHP.</p>
<hr />
<h2>Opening a File</h2>
<p>The fopen() function is used to open files in PHP.</p>
<p>The first parameter of this function contains the name of the file to be opened and the  second parameter specifies in which mode the file should be opened:</p>
<table class="ex" border="1" cellspacing="0" width="100%">
<tr>
<td>
<pre>&lt;html&gt;
&lt;body&gt;</pre>
<pre>&lt;?php
$file=fopen("welcome.txt","r");
?&gt;</pre>
<pre>&lt;/body&gt;
&lt;/html&gt;</pre>
</td>
</tr>
</table>
<p>The file may be opened in one of the following modes:</p>
<table class="ex" border="1" cellpadding="3" cellspacing="0" width="100%">
<tr valign="top">
<th align="left" width="20%">Modes</th>
<th align="left" width="80%">Description</th>
</tr>
<tr valign="top">
<td>r</td>
<td>Read only. Starts at the beginning of the file</td>
</tr>
<tr valign="top">
<td height="18">r+</td>
<td height="18">Read/Write. Starts at the beginning of the file</td>
</tr>
<tr valign="top">
<td>w</td>
<td>Write only. Opens and clears the contents of file; or creates a new file  	if it doesn&#8217;t exist</td>
</tr>
<tr valign="top">
<td>w+</td>
<td>Read/Write. Opens and clears the contents of file; or creates a new file  	if it doesn&#8217;t exist</td>
</tr>
<tr valign="top">
<td>a</td>
<td>Append. Opens and writes to the end of the file or creates a new file if  	it doesn&#8217;t exist</td>
</tr>
<tr>
<td>a+</td>
<td>Read/Append. Preserves file content by writing to the end of the file</td>
</tr>
<tr valign="top">
<td>x</td>
<td>Write only. Creates a new file. Returns FALSE and an error if file  	already exists</td>
</tr>
<tr valign="top">
<td>x+</td>
<td>Read/Write. Creates a new file. Returns FALSE and an error if file  	already exists</td>
</tr>
</table>
<p><b>Note:</b> If the fopen() function is unable to open the  specified file, it returns 0 (false).</p>
<h3>Example</h3>
<p>The following example generates a message if the fopen() function is unable  to open the specified file:</p>
<table class="ex" border="1" cellspacing="0" width="100%">
<tr>
<td>
<pre>&lt;html&gt;
&lt;body&gt;</pre>
<pre>&lt;?php
$file=fopen("welcome.txt","r") or exit("Unable to open file!");
?&gt;</pre>
<pre>&lt;/body&gt;
&lt;/html&gt;</pre>
</td>
</tr>
</table>
<hr />
<h2>Closing a File</h2>
<p>The fclose() function is used to close an open file:</p>
<table class="ex" border="1" cellspacing="0" width="100%">
<tr>
<td>
<pre>&lt;?php
$file = fopen("test.txt","r");</pre>
<pre>//some code to be executed</pre>
<pre>fclose($file);
?&gt;</pre>
</td>
</tr>
</table>
<hr />
<h2>Check End-of-file</h2>
<p>The feof() function checks if the &#8220;end-of-file&#8221; (EOF) has been reached.</p>
<p>The feof() function is useful for looping through data of unknown length.</p>
<p><b>Note:</b> You cannot read from files opened in w, a, and x mode!</p>
<table class="ex" border="1" cellspacing="0" width="100%">
<tr>
<td>
<pre>if (feof($file)) echo "End of file";</pre>
</td>
</tr>
</table>
<hr />
<h2>Reading a File Line by Line</h2>
<p>The fgets() function is used to read a single line from a file.</p>
<p><b>Note:</b> After a call to this function the file pointer has moved to the next  line.</p>
<h3>Example</h3>
<p>The example below reads a file line by line, until the end of  file is reached:</p>
<table class="ex" border="1" cellspacing="0" width="100%">
<tr>
<td>
<pre>&lt;?php
$file = fopen("welcome.txt", "r") or exit("Unable to open file!");
//Output a line of the file until the end is reached
while(!feof($file))
  {
  echo fgets($file). "&lt;br /&gt;";
  }
fclose($file);
?&gt;</pre>
</td>
</tr>
</table>
<hr />
<h2>Reading a File Character by Character</h2>
<p>The fgetc() function is used to read a single character from a file.</p>
<p><b>Note:</b> After a call to this function the file pointer moves to the next character.</p>
<h3>Example</h3>
<p>The example below reads a file character by character, until the end of  file is reached:</p>
<table class="ex" id="table1" border="1" cellspacing="0" width="100%">
<tr>
<td>
<pre>&lt;?php
$file=fopen("welcome.txt","r") or exit("Unable to open file!");
while (!feof($file))
  {
  echo fgetc($file);
  }
fclose($file);
?&gt;</pre>
</td>
</tr>
</table>
<hr />
<h2>PHP Filesystem Reference</h2>
<p>For a full reference of the PHP filesystem functions, visit our <a href="http://www.w3schools.com/php/php_ref_filesystem.asp">PHP Filesystem Reference</a>.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/phpindia.wordpress.com/27/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/phpindia.wordpress.com/27/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/phpindia.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/phpindia.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/phpindia.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/phpindia.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/phpindia.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/phpindia.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/phpindia.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/phpindia.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/phpindia.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/phpindia.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/phpindia.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/phpindia.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/phpindia.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/phpindia.wordpress.com/27/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=phpindia.wordpress.com&amp;blog=2162490&amp;post=27&amp;subd=phpindia&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://phpindia.wordpress.com/2008/01/15/php-file-handling/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ec501295341c1654cd0613192abf608b?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pankajkapil</media:title>
		</media:content>
	</item>
		<item>
		<title>PHP Include File</title>
		<link>http://phpindia.wordpress.com/2008/01/15/php-include-file/</link>
		<comments>http://phpindia.wordpress.com/2008/01/15/php-include-file/#comments</comments>
		<pubDate>Tue, 15 Jan 2008 05:45:29 +0000</pubDate>
		<dc:creator>pankajkapil</dc:creator>
				<category><![CDATA[PHP Include File]]></category>

		<guid isPermaLink="false">http://phpindia.wordpress.com/2008/01/15/php-include-file/</guid>
		<description><![CDATA[Server Side Includes (SSI) are used to create functions, headers, footers, or elements that will be reused on multiple pages. Server Side Includes You can insert the content of a file into a PHP file before the server executes it, with the include() or require() function. The two functions are identical in every way, except [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=phpindia.wordpress.com&amp;blog=2162490&amp;post=26&amp;subd=phpindia&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p class="intro">Server Side Includes (SSI) are used to create functions, headers,  footers, or elements that will be reused on multiple pages.</p>
<hr />
<h2>Server Side Includes</h2>
<p>You can insert the content of a file into a PHP file before the server  executes it, with the include() or require() function. The two functions are  identical in every way, except how they handle errors. The include() function  generates a warning (but the script will continue execution) while the require()  function generates a fatal error (and the script execution will stop after the  error).</p>
<p>These two functions are used to  create functions, headers, footers, or elements that can be reused on multiple  pages.</p>
<p>This can save the developer a considerable amount of time. This means that  you can create a standard header or menu file that you want all your web pages  to include. When the header needs to be updated, you can only  update this one include file, or when you add a new page to your site, you can simply change the  menu file (instead of updating the links on all web pages).</p>
<hr />
<h2>The include() Function</h2>
<p>The include() function takes all the text in a specified file and copies it  into the file that uses the include function.</p>
<h3>Example 1</h3>
<p>Assume that you have a standard header file, called &#8220;header.php&#8221;. To include  the header file in a page, use the include() function, like this:</p>
<table class="ex" border="1" cellspacing="0" width="100%">
<tr>
<td>
<pre>&lt;html&gt;
&lt;body&gt;</pre>
<pre>&lt;?php include("header.php"); ?&gt;</pre>
<pre>&lt;h1&gt;Welcome to my home page&lt;/h1&gt;</pre>
<pre>&lt;p&gt;Some text&lt;/p&gt;</pre>
<pre>&lt;/body&gt;
&lt;/html&gt;</pre>
</td>
</tr>
</table>
<h3>Example 2</h3>
<p>Now, let&#8217;s assume we have a standard menu file that should be used on all  pages (include files usually have a &#8220;.php&#8221;  extension). Look at the &#8220;menu.php&#8221; file below:</p>
<table class="ex" id="table1" border="1" cellspacing="0" width="100%">
<tr>
<td>
<pre>&lt;html&gt;
&lt;body&gt;</pre>
<pre>&lt;a href="http://www.w3schools.com/default.php"&gt;Home&lt;/a&gt; |
&lt;a href="http://www.w3schools.com/about.php"&gt;About Us&lt;/a&gt; |
&lt;a href="http://www.w3schools.com/contact.php"&gt;Contact Us&lt;/a&gt;</pre>
</td>
</tr>
</table>
<p>The three files, &#8220;default.php&#8221;, &#8220;about.php&#8221;, and &#8220;contact.php&#8221;  should all include the &#8220;menu.php&#8221; file.  Here is the code in &#8220;default.php&#8221;:</p>
<table class="ex" id="table2" border="1" cellspacing="0" width="100%">
<tr>
<td>
<pre>&lt;?php include("menu.php"); ?&gt;</pre>
<pre>&lt;h1&gt;Welcome to my home page&lt;/h1&gt;</pre>
<pre>&lt;p&gt;Some text&lt;/p&gt;</pre>
<pre>&lt;/body&gt;
&lt;/html&gt;</pre>
</td>
</tr>
</table>
<p>If you look at the source code of the &#8220;default.php&#8221; in a browser, it will look something like  this:</p>
<table class="ex" id="table3" border="1" cellspacing="0" width="100%">
<tr>
<td>
<pre>&lt;html&gt;
&lt;body&gt;
&lt;a href="default.php"&gt;Home&lt;/a&gt; |
&lt;a href="about.php"&gt;About Us&lt;/a&gt; |
&lt;a href="contact.php"&gt;Contact Us&lt;/a&gt;
&lt;h1&gt;Welcome to my home page&lt;/h1&gt;
&lt;p&gt;Some text&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
</td>
</tr>
</table>
<p>And, of course, we would have to do the same thing for &#8220;about.php&#8221; and &#8220;contact.php&#8221;.  By using include files, you simply have to update the text in the &#8220;menu.php&#8221;  file if you decide to rename or change the order of the links or add another web page to the site.</p>
<hr />
<h2>The require() Function</h2>
<p>The require() function is identical to include(), except that it handles  errors differently.</p>
<p>The include() function generates a warning (but the script will continue  execution) while the require() function generates a fatal error (and the script  execution will stop after the error).</p>
<p>If you include a file with the include() function and an error occurs, you  might get an error message like the one below.</p>
<p>PHP code:</p>
<table class="ex" id="table4" border="1" cellspacing="0" width="100%">
<tr>
<td>
<pre>&lt;html&gt;
&lt;body&gt;

&lt;?php
include("wrongFile.php");
echo "Hello World!";
?&gt;

&lt;/body&gt;
&lt;/html&gt;</pre>
</td>
</tr>
</table>
<p>Error message:</p>
<table class="ex" id="table5" border="1" cellspacing="0" width="100%">
<tr>
<td>
<pre><b>Warning:</b> include(wrongFile.php) [function.include]:
failed to open stream:
No such file or directory in C:\home\website\test.php on line 5</pre>
<pre><b>Warning:</b> include() [function.include]:
Failed opening 'wrongFile.php' for inclusion
(include_path='.;C:\php5\pear')
in C:\home\website\test.php on line 5</pre>
<pre>Hello World!</pre>
</td>
</tr>
</table>
<p>Notice that the echo statement is still executed! This is because a Warning  does not stop the script execution.</p>
<p>Now, let&#8217;s run the same example with the require() function.</p>
<p>PHP code:</p>
<table class="ex" id="table8" border="1" cellspacing="0" width="100%">
<tr>
<td>
<pre>&lt;html&gt;
&lt;body&gt;

&lt;?php
require("wrongFile.php");
echo "Hello World!";
?&gt;

&lt;/body&gt;
&lt;/html&gt;</pre>
</td>
</tr>
</table>
<p>Error message:</p>
<table class="ex" id="table9" border="1" cellspacing="0" width="100%">
<tr>
<td>
<pre><b>Warning:</b> require(wrongFile.php) [function.require]:
failed to open stream:
No such file or directory in C:\home\website\test.php on line 5</pre>
<pre><b>Fatal error:</b> require() [function.require]:
Failed opening required 'wrongFile.php'
(include_path='.;C:\php5\pear')
in C:\home\website\test.php on line 5</pre>
</td>
</tr>
</table>
<p>The echo statement was not executed because the script execution stopped  after the fatal error.</p>
<p>It is recommended to use the require() function instead of include(), because  scripts should not continue executing if files are missing or misnamed.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/phpindia.wordpress.com/26/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/phpindia.wordpress.com/26/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/phpindia.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/phpindia.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/phpindia.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/phpindia.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/phpindia.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/phpindia.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/phpindia.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/phpindia.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/phpindia.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/phpindia.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/phpindia.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/phpindia.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/phpindia.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/phpindia.wordpress.com/26/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=phpindia.wordpress.com&amp;blog=2162490&amp;post=26&amp;subd=phpindia&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://phpindia.wordpress.com/2008/01/15/php-include-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ec501295341c1654cd0613192abf608b?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pankajkapil</media:title>
		</media:content>
	</item>
		<item>
		<title>PHP Date()</title>
		<link>http://phpindia.wordpress.com/2008/01/15/php-date/</link>
		<comments>http://phpindia.wordpress.com/2008/01/15/php-date/#comments</comments>
		<pubDate>Tue, 15 Jan 2008 05:14:18 +0000</pubDate>
		<dc:creator>pankajkapil</dc:creator>
				<category><![CDATA[PHP Date()]]></category>

		<guid isPermaLink="false">http://phpindia.wordpress.com/2008/01/15/php-date/</guid>
		<description><![CDATA[The PHP date() function is used to format a time or a date. The PHP Date() Function The PHP date() function formats a timestamp to a more readable date and time. Syntax date(format,timestamp) Parameter Description format Required. Specifies the format of the timestamp timestamp Optional. Specifies a timestamp. Default is the current date and time [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=phpindia.wordpress.com&amp;blog=2162490&amp;post=25&amp;subd=phpindia&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p class="intro">The PHP date() function is used to format a time or a date.</p>
<hr />
<h2>The PHP Date() Function</h2>
<p>The PHP date() function formats a timestamp to a more readable date and time.</p>
<h3>Syntax</h3>
<table class="ex" border="1" cellspacing="0" width="100%">
<tr>
<td>
<pre>date(format,timestamp)</pre>
</td>
</tr>
</table>
<table class="ex" id="table1" border="1" cellpadding="3" cellspacing="0" width="100%">
<tr>
<th align="left" valign="top" width="20%">Parameter</th>
<th align="left" valign="top" width="80%">Description</th>
</tr>
<tr>
<td valign="top">format</td>
<td valign="top">Required. Specifies  	the format of the timestamp</td>
</tr>
<tr>
<td valign="top">timestamp</td>
<td valign="top">Optional. Specifies a timestamp. Default is the current  	date and time (as a timestamp)</td>
</tr>
</table>
<hr />
<h2>PHP Date &#8211; What is a Timestamp?</h2>
<p>A timestamp is the number of seconds since January 1, 1970 at 00:00:00 GMT.  This is also known as the Unix Timestamp.</p>
<hr />
<h2>PHP Date &#8211; Format the Date</h2>
<p>The first parameter in the date() function specifies how to format the  date/time. It uses letters to represent date and time formats. Here are some of  the letters that can be used:</p>
<ul>
<li>d &#8211; The day of the month (01-31)</li>
<li>m &#8211; The current month, as a number (01-12)</li>
<li>Y &#8211; The current year in four digits</li>
</ul>
<p>An overview of all the letters that can be used in the format parameter, can  be found in our <a href="http://www.w3schools.com/php/php_ref_date.asp">PHP Date reference</a>.</p>
<p>Other characters, like&#8221;/&#8221;, &#8220;.&#8221;, or &#8220;-&#8221; can also be inserted between the  letters to add additional formatting:</p>
<table class="ex" id="table2" border="1" cellspacing="0" width="100%">
<tr>
<td>
<pre>&lt;?php
echo date("Y/m/d");
echo "&lt;br /&gt;";
echo date("Y.m.d");
echo "&lt;br /&gt;";
echo date("Y-m-d");
?&gt;</pre>
</td>
</tr>
</table>
<p>The output of the code above could be something like this:</p>
<table class="ex" id="table3" border="1" cellspacing="0" width="100%">
<tr>
<td>
<pre>2006/07/11
2006.07.11
2006-07-11</pre>
</td>
</tr>
</table>
<hr />
<h2>PHP Date &#8211; Adding a Timestamp</h2>
<p>The second parameter in the date() function specifies a timestamp. This  parameter is optional. If you do not supply a timestamp, the  current time will be used.</p>
<p>In our next example we will use the mktime() function to create a timestamp for tomorrow.</p>
<p>The mktime() function returns the Unix timestamp for a specified date.</p>
<h3>Syntax</h3>
<table class="ex" id="table4" border="1" cellspacing="0" width="100%">
<tr>
<td>
<pre>mktime(hour,minute,second,month,day,year,is_dst)</pre>
</td>
</tr>
</table>
<p>To go  one day in the future we simply add one to the day argument of mktime():</p>
<table class="ex" id="table5" border="1" cellspacing="0" width="100%">
<tr>
<td>
<pre>&lt;?php
$tomorrow = mktime(0,0,0,date("m"),date("d")+1,date("Y"));
echo "Tomorrow is ".date("Y/m/d", $tomorrow);
?&gt;</pre>
</td>
</tr>
</table>
<p>The output of the code above could be something like this:</p>
<table class="ex" id="table6" border="1" cellspacing="0" width="100%">
<tr>
<td>
<pre>Tomorrow is 2006/07/12</pre>
</td>
</tr>
</table>
<hr />
<h2>PHP Date &#8211; Reference</h2>
<p>For more information about all the PHP date functions, please visit our <a href="http://www.w3schools.com/php/php_ref_date.asp">PHP Date Reference</a>.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/phpindia.wordpress.com/25/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/phpindia.wordpress.com/25/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/phpindia.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/phpindia.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/phpindia.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/phpindia.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/phpindia.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/phpindia.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/phpindia.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/phpindia.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/phpindia.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/phpindia.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/phpindia.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/phpindia.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/phpindia.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/phpindia.wordpress.com/25/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=phpindia.wordpress.com&amp;blog=2162490&amp;post=25&amp;subd=phpindia&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://phpindia.wordpress.com/2008/01/15/php-date/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ec501295341c1654cd0613192abf608b?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pankajkapil</media:title>
		</media:content>
	</item>
		<item>
		<title>PHP $_GET</title>
		<link>http://phpindia.wordpress.com/2008/01/14/php-_get/</link>
		<comments>http://phpindia.wordpress.com/2008/01/14/php-_get/#comments</comments>
		<pubDate>Mon, 14 Jan 2008 09:12:52 +0000</pubDate>
		<dc:creator>pankajkapil</dc:creator>
				<category><![CDATA[PHP $_GET]]></category>

		<guid isPermaLink="false">http://phpindia.wordpress.com/2008/01/14/php-_get/</guid>
		<description><![CDATA[The $_GET variable is used to collect values from a form with method=&#8221;get&#8221;. The $_GET Variable The $_GET variable is an array of variable names and values sent by the HTTP GET method. The $_GET variable is used to collect values from a form with method=&#8221;get&#8221;. Information sent from a form with the GET method [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=phpindia.wordpress.com&amp;blog=2162490&amp;post=24&amp;subd=phpindia&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p class="intro">The $_GET variable is used to collect values from a form with  method=&#8221;get&#8221;.</p>
<hr />
<h2>The $_GET Variable</h2>
<p>The $_GET variable is an array of variable names and values sent by the HTTP GET  method.</p>
<p>The $_GET variable is used to collect values from a form with method=&#8221;get&#8221;.  Information sent from a form with the GET method is visible to everyone (it will  be displayed in the browser&#8217;s address bar) and it has limits on the amount of  information to send (max. 100 characters).</p>
<h3>Example</h3>
<table class="ex" id="table22" border="1" cellspacing="0" width="100%">
<tr>
<td>
<pre>&lt;form action="welcome.php" method="get"&gt;
Name: &lt;input type="text" name="name" /&gt;
Age: &lt;input type="text" name="age" /&gt;
&lt;input type="submit" /&gt;
&lt;/form&gt;</pre>
</td>
</tr>
</table>
<p>When the user clicks the &#8220;Submit&#8221; button, the URL sent could look something  like this:</p>
<table class="ex" id="table23" border="1" cellspacing="0" width="100%">
<tr>
<td>
<pre>http://www.w3schools.com/welcome.php?name=Peter&amp;age=37</pre>
</td>
</tr>
</table>
<p>The &#8220;welcome.php&#8221; file can now use the $_GET variable to catch the form data  (notice that the names of the form fields will automatically be the ID keys in the $_GET array):</p>
<table class="ex" id="table24" border="1" cellspacing="0" width="100%">
<tr>
<td>
<pre>Welcome &lt;?php echo $_GET["name"]; ?&gt;.&lt;br /&gt;
You are &lt;?php echo $_GET["age"]; ?&gt; years old!</pre>
</td>
</tr>
</table>
<hr />
<h2>Why use $_GET?</h2>
<p><b>Note:</b> When using the $_GET variable all variable names and values are displayed in the  URL. So this method should not be used when sending passwords or other sensitive  information! However, because the variables are displayed in the URL, it is possible to  bookmark the page. This can be useful in some cases.</p>
<p><b>Note:</b> The HTTP GET method is not suitable on large variable values;  the value cannot exceed 100 characters.</p>
<hr />
<h2>The $_REQUEST Variable</h2>
<p>The PHP $_REQUEST variable contains the contents of both $_GET, $_POST, and $_COOKIE.</p>
<p>The PHP $_REQUEST variable can be used to get the result from form data sent  with both the GET and POST methods.</p>
<h3>Example</h3>
<pre>Welcome &lt;?php echo $_REQUEST["name"]; ?&gt;.&lt;br /&gt;
You are &lt;?php echo $_REQUEST["age"]; ?&gt; years old!</pre>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/phpindia.wordpress.com/24/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/phpindia.wordpress.com/24/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/phpindia.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/phpindia.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/phpindia.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/phpindia.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/phpindia.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/phpindia.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/phpindia.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/phpindia.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/phpindia.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/phpindia.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/phpindia.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/phpindia.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/phpindia.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/phpindia.wordpress.com/24/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=phpindia.wordpress.com&amp;blog=2162490&amp;post=24&amp;subd=phpindia&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://phpindia.wordpress.com/2008/01/14/php-_get/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ec501295341c1654cd0613192abf608b?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pankajkapil</media:title>
		</media:content>
	</item>
		<item>
		<title>PHP Forms and User Input</title>
		<link>http://phpindia.wordpress.com/2008/01/14/php-forms-and-user-input/</link>
		<comments>http://phpindia.wordpress.com/2008/01/14/php-forms-and-user-input/#comments</comments>
		<pubDate>Mon, 14 Jan 2008 08:47:34 +0000</pubDate>
		<dc:creator>pankajkapil</dc:creator>
				<category><![CDATA[PHP Forms and User Input]]></category>

		<guid isPermaLink="false">http://phpindia.wordpress.com/2008/01/14/php-forms-and-user-input/</guid>
		<description><![CDATA[The PHP $_GET and $_POST variables are used to retrieve information from forms, like user input. PHP Form Handling The most important thing to notice when dealing with HTML forms and PHP is that any form element in an HTML page will automatically be available to your PHP scripts. Form example: &#60;html&#62; &#60;body&#62; &#60;form action="welcome.php" [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=phpindia.wordpress.com&amp;blog=2162490&amp;post=23&amp;subd=phpindia&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p class="intro">The PHP $_GET and $_POST variables are used to retrieve information from forms, like user input.</p>
<hr />
<h2>PHP Form Handling</h2>
<p>The most important thing to notice when dealing with HTML forms and PHP is  that any form element in an HTML page will <b>automatically</b> be available to your PHP scripts.</p>
<p><b>Form example:</b></p>
<table class="ex" border="1" cellspacing="0" width="100%">
<tr>
<td>
<pre>&lt;html&gt;
&lt;body&gt;</pre>
<pre>&lt;form action="welcome.php" method="post"&gt;
Name: &lt;input type="text" name="name" /&gt;
Age: &lt;input type="text" name="age" /&gt;
&lt;input type="submit" /&gt;
&lt;/form&gt;</pre>
<pre>&lt;/body&gt;
&lt;/html&gt;</pre>
</td>
</tr>
</table>
<p>The example HTML page above contains two input fields and a submit button.  When the user fills in this form and click on the submit button, the form data  is sent to the &#8220;welcome.php&#8221;  file.</p>
<p>The &#8220;welcome.php&#8221; file looks like this:</p>
<table class="ex" border="1" cellspacing="0" width="100%">
<tr>
<td>
<pre>&lt;html&gt;
&lt;body&gt;</pre>
<pre>Welcome &lt;?php echo $_POST["name"]; ?&gt;.&lt;br /&gt;
You are &lt;?php echo $_POST["age"]; ?&gt; years old.</pre>
<pre>&lt;/body&gt;
&lt;/html&gt;</pre>
</td>
</tr>
</table>
<p>A sample output of the above script may be:</p>
<table class="ex" border="1" cellspacing="0" width="100%">
<tr>
<td>
<pre>Welcome John.
You are 28 years old.</pre>
</td>
</tr>
</table>
<p>The PHP $_GET and $_POST variables will be explained in the next chapters.</p>
<hr />
<h2>Form Validation</h2>
<p>User input should be validated whenever possible. Client side validation is  faster, and will reduce server load.</p>
<p>However, any site that gets enough traffic to worry about server resources,  may also need to worry about site security. You should always use server side validation if  the form accesses a database.</p>
<p>A good way to validate a form on the server is to post  the form to itself, instead of jumping to a different page. The user will then  get the error messages on the same page as the form. This makes it easier to  discover the error.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/phpindia.wordpress.com/23/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/phpindia.wordpress.com/23/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/phpindia.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/phpindia.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/phpindia.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/phpindia.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/phpindia.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/phpindia.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/phpindia.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/phpindia.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/phpindia.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/phpindia.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/phpindia.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/phpindia.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/phpindia.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/phpindia.wordpress.com/23/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=phpindia.wordpress.com&amp;blog=2162490&amp;post=23&amp;subd=phpindia&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://phpindia.wordpress.com/2008/01/14/php-forms-and-user-input/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ec501295341c1654cd0613192abf608b?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pankajkapil</media:title>
		</media:content>
	</item>
		<item>
		<title>PHP Functions</title>
		<link>http://phpindia.wordpress.com/2008/01/14/php-functions/</link>
		<comments>http://phpindia.wordpress.com/2008/01/14/php-functions/#comments</comments>
		<pubDate>Mon, 14 Jan 2008 07:28:25 +0000</pubDate>
		<dc:creator>pankajkapil</dc:creator>
				<category><![CDATA[PHP Functions]]></category>

		<guid isPermaLink="false">http://phpindia.wordpress.com/2008/01/14/php-functions/</guid>
		<description><![CDATA[The real power of PHP comes from its functions. In PHP &#8211; there are more than 700 built-in functions available. PHP Functions In this tutorial we will show you how to create your own functions. For a reference and examples of the built-in functions, please visit our PHP Reference. Create a PHP Function A function [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=phpindia.wordpress.com&amp;blog=2162490&amp;post=22&amp;subd=phpindia&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p class="intro">The real power of PHP comes from its functions.</p>
<p class="intro">In PHP &#8211; there are more than 700 built-in functions available.</p>
<hr />
<h2>PHP Functions</h2>
<p>In this tutorial we will show you how to create your own functions.</p>
<p>For a reference and examples of the built-in functions, please visit our <a href="http://www.w3schools.com/php/default.asp">PHP Reference.</a></p>
<hr />
<h2>Create a PHP Function</h2>
<p>A function is a block of code that can be executed whenever we need it.</p>
<p>Creating PHP functions:</p>
<ul>
<li>All functions start with the word &#8220;function()&#8221;</li>
<li>Name the function &#8211; It should be possible to understand what the  	function does by its name. The name can start with a letter or  	underscore (not a number)</li>
<li>Add a &#8220;{&#8220;  &#8211; The function code starts after the opening  	curly brace</li>
<li>Insert the function code</li>
<li>Add a &#8220;}&#8221;  &#8211; The function is finished by a closing curly brace</li>
</ul>
<h3>Example</h3>
<p>A simple function that writes my name when it is called:</p>
<table class="ex" id="table7" border="1" cellspacing="0" width="100%">
<tr>
<td>
<pre>&lt;html&gt;
&lt;body&gt;</pre>
<pre>&lt;?php
function writeMyName()
  {
  echo "Kai Jim Refsnes";
  }</pre>
<pre>writeMyName();
?&gt;</pre>
<pre>&lt;/body&gt;
&lt;/html&gt;</pre>
</td>
</tr>
</table>
<hr />
<h2>Use a PHP Function</h2>
<p>Now we will use the function in a PHP script:</p>
<table class="ex" id="table8" border="1" cellspacing="0" width="100%">
<tr>
<td>
<pre>&lt;html&gt;
&lt;body&gt;</pre>
<pre>&lt;?php
function writeMyName()
  {
  echo "Kai Jim Refsnes";
  }</pre>
<pre>echo "Hello world!&lt;br /&gt;";
echo "My name is ";
writeMyName();
echo ".&lt;br /&gt;That's right, ";
writeMyName();
echo " is my name.";
?&gt;</pre>
<pre>&lt;/body&gt;
&lt;/html&gt;</pre>
</td>
</tr>
</table>
<p>The output of the code above will be:</p>
<table class="ex" id="table9" border="1" cellspacing="0" width="100%">
<tr>
<td>
<pre>Hello world!
My name is Kai Jim Refsnes.
That's right, Kai Jim Refsnes is my name.</pre>
</td>
</tr>
</table>
<hr />
<h2>PHP Functions &#8211; Adding parameters</h2>
<p>Our first function (writeMyName()) is a very simple function. It only writes a  static string.</p>
<p>To add more functionality to a function, we can add parameters. A parameter is just like a variable.</p>
<p>You may have noticed the parentheses after the function name,  like: writeMyName(). The parameters are specified inside the parentheses.</p>
<h3>Example 1</h3>
<p>The following example will write different first names, but the same last  name:</p>
<table class="ex" id="table10" border="1" cellspacing="0" width="100%">
<tr>
<td>
<pre>&lt;html&gt;
&lt;body&gt;</pre>
<pre>&lt;?php
function writeMyName($fname)
  {
  echo $fname . " Refsnes.&lt;br /&gt;";
  }</pre>
<pre>echo "My name is ";
writeMyName("Kai Jim");</pre>
<pre>echo "My name is ";
writeMyName("Hege");</pre>
<pre>echo "My name is ";
writeMyName("Stale");
?&gt;</pre>
<pre>&lt;/body&gt;
&lt;/html&gt;</pre>
</td>
</tr>
</table>
<p>The output of the code above will be:</p>
<table class="ex" id="table11" border="1" cellspacing="0" width="100%">
<tr>
<td>
<pre>My name is Kai Jim Refsnes.
My name is Hege Refsnes.
My name is Stale Refsnes.</pre>
</td>
</tr>
</table>
<h3>Example 2</h3>
<p>The following function has two parameters:</p>
<table class="ex" id="table12" border="1" cellspacing="0" width="100%">
<tr>
<td>
<pre>&lt;html&gt;
&lt;body&gt;</pre>
<pre>&lt;?php
function writeMyName($fname,$punctuation)
  {
  echo $fname . " Refsnes" . $punctuation . "&lt;br /&gt;";
  }</pre>
<pre>echo "My name is ";
writeMyName("Kai Jim",".");</pre>
<pre>echo "My name is ";
writeMyName("Hege","!");</pre>
<pre>echo "My name is ";
writeMyName("Ståle","...");
?&gt;</pre>
<pre>&lt;/body&gt;
&lt;/html&gt;</pre>
</td>
</tr>
</table>
<p>The output of the code above will be:</p>
<table class="ex" id="table13" border="1" cellspacing="0" width="100%">
<tr>
<td>
<pre>My name is Kai Jim Refsnes.
My name is Hege Refsnes!
My name is Ståle Refsnes...</pre>
</td>
</tr>
</table>
<hr />
<h2>PHP Functions &#8211; Return values</h2>
<p>Functions can also be used to return  values.</p>
<h3>Example</h3>
<table class="ex" id="table14" border="1" cellspacing="0" width="100%">
<tr>
<td>
<pre>&lt;html&gt;
&lt;body&gt;</pre>
<pre>&lt;?php
function add($x,$y)
  {
  $total = $x + $y;
  return $total;
  }</pre>
<pre>echo "1 + 16 = " . add(1,16);
?&gt;</pre>
<pre>&lt;/body&gt;
&lt;/html&gt;</pre>
</td>
</tr>
</table>
<p>The output of the code above will be:</p>
<pre>1 + 16 = 17</pre>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/phpindia.wordpress.com/22/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/phpindia.wordpress.com/22/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/phpindia.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/phpindia.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/phpindia.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/phpindia.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/phpindia.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/phpindia.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/phpindia.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/phpindia.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/phpindia.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/phpindia.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/phpindia.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/phpindia.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/phpindia.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/phpindia.wordpress.com/22/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=phpindia.wordpress.com&amp;blog=2162490&amp;post=22&amp;subd=phpindia&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://phpindia.wordpress.com/2008/01/14/php-functions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ec501295341c1654cd0613192abf608b?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pankajkapil</media:title>
		</media:content>
	</item>
	</channel>
</rss>
