<?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>GeekScribes &#187; PHP Lessons</title>
	<atom:link href="http://www.geekscribes.net/blog/category/tech-posts/programming/php-lessons/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.geekscribes.net/blog</link>
	<description>Bringing geekiness to the world</description>
	<lastBuildDate>Tue, 07 Feb 2012 15:21:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>PHP Lessons 9: Session and Cookies</title>
		<link>http://www.geekscribes.net/blog/2010/03/19/php-lessons-9-session-and-cookies/</link>
		<comments>http://www.geekscribes.net/blog/2010/03/19/php-lessons-9-session-and-cookies/#comments</comments>
		<pubDate>Fri, 19 Mar 2010 09:34:20 +0000</pubDate>
		<dc:creator>Guest-GS</dc:creator>
				<category><![CDATA[PHP Lessons]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[How To]]></category>
		<category><![CDATA[Lessons]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.geekscribes.net/blog/?p=780</guid>
		<description><![CDATA[Hello there, back with some PHP lessons. It&#8217;s been quite a while. Got loads of projects to deal with at work and wasn&#8217;t feeling like typing codes at home. This lesson will deal about session ($_SESSION) and cookies ($_COOKIES)&#8230;(This kind of cookie has nothing to do with cookies our grand-mother used to cook for us [...]<p>This article comes from <a href="http://www.geekscribes.net/blog">GeekScribes</a><br/><br/><a href="http://www.geekscribes.net/blog/2010/03/19/php-lessons-9-session-and-cookies/">PHP Lessons 9: Session and Cookies</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Hello there, back with some PHP lessons. It&#8217;s been quite a while. Got loads of projects to deal with at work and wasn&#8217;t feeling like typing codes at home.</p>
<p>This lesson will deal about session ($_SESSION) and cookies ($_COOKIES)&#8230;(This kind of cookie has nothing to do with cookies our grand-mother used to cook for us <img src='http://www.geekscribes.net/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  )</p>
<p><span id="more-780"></span></p>
<p><strong>SESSIONS:</strong></p>
<p><strong>What are session and how can they be useful?</strong></p>
<p>Sessions in PHP are meant to keep track and store data for a particular user while they browse our site or pages. For example, with a login system, when the user logs in, PHP must have a way to keep track of the user&#8217;s status and with this kind of info, we can allow registered user to access private areas and so on. We can also store other data like what time they logged on, and show messages like: &#8220;You&#8217;ve been here for X minutes&#8221;.</p>
<p>When you start a SESSION, a random Session Id is stored in a COOKIE and the default name is PHPSESSID. Yes, even if it&#8217;s a SESSION, the value is also stored in a COOKIE an placed on your computer. The advantage of SESSION is, even if the user has cookies disable on his browser, SESSION will still keep track of user info, because, SESSION not only adds PHPSESSID to a cookie, but all values you assign to a SESSION, are also stored in a file on your server.</p>
<p><strong>How do we start a SESSION?</strong></p>
<p>The answer is simple, you just have to add this line on code on top of your page, before any html or php code whatsoever. It HAS to be at the very top, else you can get error messages.</p>
<pre>&lt;?php
    session_start();

    //other stuff below
?&gt;
</pre>
<p>Author&#8217;s note : Sometimes, when declaring session_start(), you might get a fancy notice which will drive you crazy. I will tell you about it later in this chapter.</p>
<p>Let&#8217;s try something with SESSION. We will declare a SESSION, assign a value to it, and retrieve the value. Code&#8217;s below:</p>
<pre>&lt;?php
     session_start(); 

     $_SESSION['view'] = 1; // assign value to session
     echo "Pageviews = ". $_SESSION['view']; //retrieving the value
?&gt;
</pre>
<p>Let&#8217;s analyze this,</p>
<p>1) We declared our session on top of everything.<br />
2) we assigned the value of 1 to the SESSION array at position &#8220;view&#8221;: $_SESSION['view']. We hence called the SESSION, &#8220;view&#8221;. Yep, $_SESSION is just an array!<br />
3) We echo out the value of the SESSION.</p>
<p>If you run this code, it will print 1. Cool huh?</p>
<p>With this, we can determine how many times a page has been viewed. The code below:</p>
<pre>&lt;?php
    session_start();  //declare session

    if(isset($_SESSION['view']))
       $_SESSION['view'] = $_SESSION['view']  + 1;

    else
       $_SESSION['view'] = 1;

   echo 'You viewed this page '. $_SESSION['view'].' times.';
?&gt;   
</pre>
<p>This one looks a bit different, we added a condition to check the value of our SESSION.</p>
<p>First, if the session is already set (isset()), We just add 1 to it. According to our condition here, if it&#8217;s there, lets just increment it, else we default the value to one.</p>
<p>If you try this code, keeps refreshing your page, and you will see the numbers increasing in value as you refresh.</p>
<p>As you already noticed by now, $_SESSION is also an Array.</p>
<pre>&lt;?php
   session_start();

   $_SESSION['firstname']   = 'John'; // Assign value to session called firstname. (Hello again, Mr. John!)
   $_SESSION['lastname']    = 'Dingo';
   $_SESSION['age']         = '18';
   $_SESSION['location']    = 'Mauritius';
   $_SESSION['sex']         = 'Male';

   echo '&lt;pre&gt;';
      print_r($_SESSION);
   echo '&lt;/pre&gt;';
?&gt;</pre>
<p>Try the code above, it will print an array of the $_SESSION we declare, and yes, it will echo ALL the session we declare, including the view $_SESSION from before. But now, why is it echoing out a $_SESSION that we didn&#8217;t declare in the script above? Well, remember, SESSION are being stored on a file on your server. The $_SESSION called &#8220;view&#8221; is still in there and we are looking at a complete Array of all SESSIONS that has been set.</p>
<p>How do we get rid of this view SESSION then?</p>
<p>In order to achieve this, we have to unset the session view. The name says it all because the built-in function we are going to use is called : unset();</p>
<p>Try the code below:</p>
<pre>&lt;?php
   session_start();

   $_SESSION['firstname']  = 'John'; // You again, Mr. John?
   $_SESSION['lastname']   = 'Dingo'; //
   $_SESSION['age']        = '18';
   $_SESSION['location']   = 'Mauritius';
   $_SESSION['sex']        = 'Male';

   unset($_SESSION['view']); //gets rid of the view 

   echo '&lt;pre&gt;';
      print_r($_SESSION);
   echo '&lt;/pre&gt;';
?&gt;
</pre>
<p>Refresh your page and TADA! the $_SESSION called view is gone. Now, since $_SESSION is an array. We can use the foreach() loop as well as the for() loop to deal with Multidimensional Arrays. <img src='http://www.geekscribes.net/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>Let&#8217;s experiment. Code below:</p>
<pre>&lt;?php
    session_start();

    $_SESSION['msg'] = array(); //We assign our message session as an empty array;

    $_SESSION['msg']['msg_one'] = 'Hello this is message one.';
    $_SESSION['msg']['msg_two'] = 'Hello this is message two.';
    $_SESSION['msg']['msg_three'] = 'Hello this is message three.';

    echo $_SESSION['msg']; // This will only output Array to our browser. So we don't see any values

    echo '&lt;hr /&gt;';

    if(is_array($_SESSION['msg'])){
       foreach($_SESSION['msg'] as $myMsg){
          echo $myMsg.'&lt;br /&gt;';
       }        
    }

?&gt;
</pre>
<p>As you can see here, when we  echo $_SESSION['msg'];, it only outputs Array to our browser. We need to access the data in this array. Remember the foreach loop? It comes in handy there, we are iterating over the Array and outputting it&#8217;s value. The results will look like this:</p>
<pre>Hello this is message one.</pre>
<pre>Hello this is message two.</pre>
<pre>Hello this is message three.
</pre>
<p>You will notice a new little function called is_array(). This is a built-in function that checks if the argument being pass in an array. This function returns true or false, in our case, it will return true since $_SESSION['msg'] was set as an array to begin with.</p>
<p>Sometimes, these built-in functions comes in handy especially when you&#8217;re dealing with dynamically generated data.</p>
<p>You can start a session, but you can also destroy a session. Yes, you can. How?</p>
<p>Just by adding session_destroy() in your script.</p>
<p>Note that, when you close all your browsers, the session is automatically destroyed or cleared if you prefer. But some browsers like Mozilla Firefox sometimes asks you if you would like to save data before closing, if you choose yes, then I believe all the SESSIONS are preserved.</p>
<p>Earlier, i told about session_start() generating an ugly PHP Notice. This is true. Even if it&#8217;s a built-in function. How come? Well, let me explain something. In your PHP Configuration (php.ini file), there a line which says:</p>
<pre>session.auto_start = 0 or session.auto_start = 1
</pre>
<p>What this means is, when &#8216;session.auto_start = 1&#8242;, PHP has the power to start a session for you automatically, without you having to put session_start() at top of your script and if it is 0, then you will have to add session_start() at top of your script. PHP starting a session automatically for me. Cool huh? Not so quick pals, this can cause some serious damage later. Follow on.</p>
<p>Let&#8217;s assume the server your using right now, has session.auto_start set to 1. With this, you might say, ok, PHP is doing it for me, so I won&#8217;t bother adding session_start() in my script. But, what if you move your site on another server, and this another server PHP configuration has session.auto_start set to 0? That means your scripts won&#8217;t work and you will get some ugly error messages and yes YOU will have to go in your scripts and add session_start() everywhere where your scripts are using session.</p>
<p>Now, since we are good programmers, we must find a way to make our scripts cross-server. Bypassing this problem is actually quite easy. When a session is declared, a session_id is being generated. Remember, I told you that at the beginning of the lesson? In PHP, you can check if a session_id exist. We use the session_id() built-in function. With this, we can make a condition to bypass our problem. Code below:</p>
<pre>&lt;?php
   if(!session_id()) { session_start(); }

   $_SESSION['msg'] = array(); //We assign our message session as an empty array;

   $_SESSION['msg']['msg_one'] = 'Hello this is message one.';
   $_SESSION['msg']['msg_two'] = 'Hello this is message two.';
   $_SESSION['msg']['msg_three'] = 'Hello this is message three.';

   echo $_SESSION['msg']; // This will only output Array to our browser. So we don't see any values

   echo '&lt;hr /&gt;';

   if(is_array($_SESSION['msg'])){
      foreach($_SESSION['msg'] as $myMsg){
         echo $myMsg.'&lt;br /&gt;';
?&gt;
</pre>
<p>Have a look at the very first line in the code above. The condition says, if there&#8217;s no session_id, then we use the session_start. This will get rid of the pain <img src='http://www.geekscribes.net/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> . I strongly advise that you use this method when starting a session. Believe me, it will save you some time later.</p>
<p>That&#8217;s it for $_SESSION. Moving on with $_COOKIES.</p>
<p><strong>Cookies</strong></p>
<p>Unlike the cookies we used to eat, this one is a bit tricky and less tasty, and the syntax is different from SESSION. We don&#8217;t start a cookie, we SET a cookie. I believe you all know what browser Cookies are. It&#8217;s a way to store data on the users computer in small files.</p>
<p>When a website places a cookie on your PC, it&#8217;s to determine wether you have been on this site recently. Usually when you login on a website, there&#8217;s a checkbox which says &#8220;Remember Me&#8221;, if you check it, the script will place a cookie on you computer, after two days, when you go to that same site, the script will check if a cookie exist, if it is, you won&#8217;t have to login again, you&#8217;re already logged in. Cool huh .. The syntax for COOKIE is below:</p>
<pre>setcookie(name, value, expire, path, domain, secure); 

name     = the name of the cookie
value    = the value of the cookie
expire   = the amount of time the cookie will remain alive
path     = which path on your server you want the cookie to be accessible
domain   = the domain that the cookie is available
secure   = Indicates that the cookie should only be transmitted over a secure HTTPS connection from the client.
</pre>
<p>Below is an example of how to work with cookie:</p>
<pre>&lt;?php

    if(isset($_COOKIE['username'])){
       echo "You were there recently ".$_COOKIE['username']." Nice to have you back pal";
    }
    else{
       echo "Hi, you're new here. What is you name?";
       setcookie('username','John',time()+3600,'/');
    }

?&gt;</pre>
<p>In the code above, we first make a condition to see if a $_COOKIE name &#8216;username&#8217; was set. If it was, then it means the user was here recently. Else, it&#8217;s his first time, so we show him a message stating that his new, and then, we set a cookie using the setcookie function.</p>
<p>We named our cookie username, we gave it a value of John ( In this example, the value can be anything ), then we set the expire time, in our case, the cookie will expire in 1 hour (in seconds, 1 hour = 3600 seconds). The last parameter is the path; I want this cookie to be accessible everywhere on my server. After expiry, it means the cookie is no longer valid. If the user returned after say, 5 hours, he&#8217;ll get the message destined to new users. This is useful when you have checkboxes like &#8220;Remember me for a day&#8221;. Set the expiry of the cookie to one day, and you&#8217;re done.</p>
<p>You will notice that I omitted the domain and secure parameter, it is optional.</p>
<p>If you run the code, you will get: <strong>Hi, you&#8217;re new here. What is you name?</strong>&#8230; and a cookie will be set.</p>
<p>But if you refresh it again, you will get: <strong>You were here recently John. Nice to have you back pal!</strong>, since our condition saw a cookie named &#8220;check&#8221;.</p>
<p>Remember, John is the value of our cookie, that&#8217;s why we get his name in th first if statement.</p>
<p>To get an entire $_COOKIE Array, just run the code below:</p>
<pre>&lt;?php

   echo '&lt;pre&gt;';
   print_r($_COOKIE);
   echo '&lt;/pre&gt;';

?&gt;
</pre>
<p>You might get a big Array along with a bunch of values, depending on how many sites has a cookie on your PC <img src='http://www.geekscribes.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Now that we know how to set a cookie, but how do I delete the cookie? Interesting question. Unlike SESSION, a cookie cannot be delete using the unset() function, neither exist a built-in function call destroy_cookie(). You can&#8217;t go on deleting files on the user&#8217;s machine, can you?</p>
<p>To delete a cookie, you simply set the expire time in the past.:</p>
<p>Code below:</p>
<pre>&lt;?php

   if(isset($_COOKIE['username'])){
      setcookie('username','john',time()-3600,'/');
      echo 'Cookie has been deleted.';
   }

   echo '&lt;pre&gt;';
      print_r($_COOKIE);
   echo '&lt;/pre&gt;';
?&gt;
</pre>
<p>In our if statement, have a look at the setcookie function and analyze the parameters, something has changed. Notice the time()-3600 . Before we did time()+3600. But we wanted to erase it, so we defined the time 1 hour in the past. This will get rid of the cookie. Have a look at the Array, you will notice that John isn&#8217;t there anymore. He&#8217;s gone. Poor guy. He&#8217;ll be back, don&#8217;t worry.</p>
<p>Cool, we know how to set a cookie. But what about that time() function you keep talking about?</p>
<p>Well, PHP allows you to work with time. The function time() doesn&#8217;t actually return something like 19:50:23. Instead,it returns the current time as a UNIX TimeStamp (the number of seconds since January 1 1970 00:00:00 GMT). This is used as a reference time point to know much time elapsed. It&#8217;s the computer&#8217;s way of asking: &#8220;How long has it before you have eaten?&#8221;. So you figure out when you last ate, check what time it is now, and do a substraction and say, &#8220;5 mins ago&#8221;.If you echo time(), you will get something similar to this:</p>
<pre>1268422287</pre>
<p>Yes,a bunch of numbers. What the hell is that? That&#8217;s how a computer knows &#8220;Now&#8221;. 7 seconds ago would be:</p>
<pre>1268422280</pre>
<p>I want a good formatted time. Ok, to compensate for the delay of the PHP Lessons, I will show you some examples of how you can format a date and time using the number of seconds return by time(). The time() function, doesn&#8217;t take any parameters. In order to get a nice format of the date and time. We should use the date() function in addition with the time() function. Example below:</p>
<pre>&lt;?php
   echo 'Current time is : '. date('Y-m-d H:i:s',time()); // outputs Current time is : 2010-03-12 23:35:40
?&gt;
</pre>
<p>This code will give you the current time. Well, depending on your server, you might get a time 4 hours earlier than that. If that&#8217;s the case, to get the current time, you will need to offset your date() function. Example below:</p>
<pre>&lt;?php
   echo 'Current time is : '. date('Y-m-d H:i:s',time() + 14400);
?&gt;
</pre>
<p>You already noticed, we added 14400 with the time() function. Why 14400? Little maths below:</p>
<pre>1 minutes           = 60 seconds, So
1 hour              = 60 minutes, So to get the numbers of seconds in 1 hour, we do
1 hour in seconds   = 60 seconds * 60 minutes which = 3600

Now we know 3600 seconds equals 1 hour.
To get an offset of 4 hours, we multiply 3600 by 4. The result is 14400.
</pre>
<p>Next we add it to our time() function. Isn&#8217;t PHP great?</p>
<p>To get a list of available format of date and time, I strongly suggest you visit this link : http://php.net/manual/en/function.date.php.</p>
<p>While i&#8217;m at my little &#8216;compensating for the delay of lesson&#8217;, let&#8217;s go back in the past where we used to talk about user defined function.</p>
<p>This is a bonus for you.</p>
<p>When we create our own function, we can pass in arguments, as many as we want. What if one day, our function requires unlimited number of arguments? Supposed some numbers are being returned from a database, we want to make some maths or whatever with those numbers, and it so happens we are getting about 1000 rows of numbers. Are we going to write a function that takes 1000 arguments? If you have the time to type all that, then good luck. But instead of typing, let me show you how to create a function of your own, that can take unlimited amounts of args.</p>
<pre>&lt;?php
   function unlimitedArgs(){

      $arguments = func_get_args(); // returns an array of arguments passed to the function when calling it

      foreach($arguments as $args){
         return array_sum($args);
      }
   }

   $someArray = array(1,2,3,4,5);

   echo unlimitedArgs($someArray);

?&gt;
</pre>
<p>Let&#8217;s analyze, first, for a beginner, things looks weird, because we are creating a function that doesn&#8217;t take any arguments, and yet, when we call that function, we are passing an array as it&#8217;s arguments. Have a look at the function, we have this line:</p>
<pre>$arguments = func_get_args();
</pre>
<p>func_get_args() returns an array of any arguments passed to the function even if we didn&#8217;t supply it when created the function itself. This way, we can pass as many arguments as we want. In our example, our argument is an array containing numbers. Our function simply iterates over the array of arguments created by func_get_args, then we use the array_sum function to sum up all the values in the array. Our result is 15.</p>
<p>array_sum(Array) simply sum all the values in the given array.</p>
<p>Ok, I believe this is it for this lesson. If you didn&#8217;t understand the last part, comments are open for questions! <img src='http://www.geekscribes.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Nice reading.</p>
<h3 style="text-align: center;">This article was contributed by Tipa of <a  title="Mu-Anime: Tipa's Site" href="http://www.mu-anime.com/" target="_blank">Mu-Anime</a></h3>

<p>This article comes from <a  href="http://www.geekscribes.net/blog">GeekScribes</a><br/><br/><a  href="http://www.geekscribes.net/blog/2010/03/19/php-lessons-9-session-and-cookies/">PHP Lessons 9: Session and Cookies</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.geekscribes.net/blog/2010/03/19/php-lessons-9-session-and-cookies/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>PHP Lessons 8: Server Constants and HTML Forms</title>
		<link>http://www.geekscribes.net/blog/2009/12/10/php-lessons-8-server-constants-and-html-forms/</link>
		<comments>http://www.geekscribes.net/blog/2009/12/10/php-lessons-8-server-constants-and-html-forms/#comments</comments>
		<pubDate>Thu, 10 Dec 2009 14:49:56 +0000</pubDate>
		<dc:creator>Guest-GS</dc:creator>
				<category><![CDATA[PHP Lessons]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[How To]]></category>
		<category><![CDATA[Lessons]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.geekscribes.net/blog/?p=760</guid>
		<description><![CDATA[Hello there, it&#8217;s been a while, I&#8217;ve been very busy with work and some personal project, so i had to delay the PHP courses, but anyway, I&#8217;m back and today we&#8217;ll have a look at Server Constants. Take a look at www.geekscribes.net, on the right side, we have a search form, when you type in [...]<p>This article comes from <a href="http://www.geekscribes.net/blog">GeekScribes</a><br/><br/><a href="http://www.geekscribes.net/blog/2009/12/10/php-lessons-8-server-constants-and-html-forms/">PHP Lessons 8: Server Constants and HTML Forms</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Hello there, it&#8217;s been a while, I&#8217;ve been very busy with work and some personal project, so i had to delay the PHP courses, but anyway, I&#8217;m back and today we&#8217;ll have a look at Server Constants.</p>
<p>Take a look at www.geekscribes.net, on the right side, we have a search form, when you type in a search keyword and press Enter, the page loads and it fetch every results according to what you typed. Ever wonder how it works? Don&#8217;t go any further, today I will show you bring a boring html form to life.</p>
<p>Before I start, if you missed the array tutorials, then please, go to the link below, and read the post, give it a try.. because you&#8217;ll need to understand how arrays work in order to understand this lesson fully.</p>
<p><span id="more-760"></span></p>
<p>Here&#8217;s the link:</p>
<p><a  title="PHP Lessons on Arrays @ Geekscribes" href="http://www.geekscribes.net/blog/2009/08/11/php-lessons-arrays/" target="_blank">http://www.geekscribes.net/blog/2009/08/11/php-lessons-arrays/</a></p>
<p>So let&#8217;s begin.. Server Constants are also called Predefined Variables, which are just arrays in fact. I will list some of them, but today, we&#8217;ll have a look at two of them..Below is a list:</p>
<pre>$_SERVER:     This grabs almost all information about the server your website resides on.

$_GET:        The HTTP GET variables are in there

$_POST:       HTTP POST Variables (Very useful with forms)

$_FILES:      Used with forms also, but only for upload purposes. LIke uploading files to a server. Think Rapidshare.

$_REQUEST:    HTTP Request variables (We can say it is a mix of $_GET and $_POST.
              But don't rely on it too much. The only way to rely on it is to use the function array_map() ).
              Also, it's a bit unsecured to use this one, so avoid!

$_SESSION:    Session Variables
              (This is a handy built-in function use to store data. Like Username, Password, User Clicks.
              It can be useful, but can be hard to understand).

$_COOKIE:     HTTP Cookies.
              (This is use to store information on your computer. Like which preference you choosed for a website.
              Or if you checked Remember Me when logged in, a cookie is set on your computer.)</pre>
<p>We&#8217;ll deal with $_SESSION and $_COOKIE in a later lesson, so no worries. <img src='http://www.geekscribes.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Today, we&#8217;ll have a look at $_GET and $_POST..and in order for you to understand, we will use an HTML Form to send a Request to the server.. Now, what is &#8220;send Request to the server&#8221;? Basically, you are making a request for a resource from the server, or are sending something to it. Whatever you put in a form is sent to the server in a special message (or request). The server can then use this to determine what you want and what to do.</p>
<p>There are two methods of sending requests, namely GET and POST. When you use GET, whatever data to be sent is passed in the URL (or action) if the form, in plain text. Using POST, the data is sent in the background making the transfer invisible to the user. Following logic, you won&#8217;t be sending login information via GET since the password would be visible in the address bar in plain text. For this, you&#8217;ll use POST. For other uses, such as getting an item&#8217;s price, GET is perfectly acceptable.</p>
<p>Note, if no value is specified for the action attribute, it means that the page refers to itself. If the page is &#8220;test.php&#8221;, it&#8217;s as if action was set to &#8220;test.php&#8221;. Also, if you don&#8217;t set a method, by default it&#8217;s &#8220;GET&#8221;. So beware if you&#8217;ll be using it to send passwords etc.</p>
<pre>&lt;form method="post" action="name.php"&gt;
   &lt;label for="name"&gt;Type your name&lt;/label&gt;
   &lt;input type="text" name="name" /&gt;
   &lt;input type="submit" name="submit" value="Output my name" /&gt;
&lt;/form&gt;</pre>
<p>Ok, i won&#8217;t go through all this, you should at least have a fair knowlegde of HTML if you are studying PHP, but what I will point out is, the part where it says &#8221; &lt;form method=&#8221;post&#8221; action=&#8221;name.php&#8221;&gt; &#8221;</p>
<p>The &#8220;method&#8221; attribute in the form tag is set to post, which means we are going to use POST ( $_POST for php ) and the page to process the code is the same where our form lives, which is set in the &#8220;action&#8221; attribute of the form tag, so it&#8217;s set to nothing, which means, use the same page as our form, the PHP Code will be in the same page.</p>
<p>Ok, let&#8217;s make a test. Fire up your code editor or use the old notepad, and type that in a file, say &#8220;test.php&#8221;. It HAS to end in .php, not .html or .htm, even if it includes HTML codes. If it doesn&#8217;t end in .php, it won&#8217;t get pre-processed, and you&#8217;ll just see your PHP code in plain text.</p>
<pre>&lt;?php</pre>
<pre>  if(isset($_POST['submit']))
  {
     echo "&lt;pre&gt;";
     print_r($_POST);
     echo "&lt;/pre&gt;";
  }</pre>
<pre>?&gt;</pre>
<pre>&lt;form method="post" action=""&gt;
   &lt;label for="name"&gt;Type your name&lt;/label&gt;
   &lt;input type="text" name="name" /&gt;
   &lt;input type="submit" name="submit" value="Output my name" /&gt;
&lt;/form&gt;</pre>
<p>Type in your name in the input box, press enter and see the results.. My output was like this:</p>
<pre>Array
(
   [name] =&gt; Kevin
   [submit] =&gt; Output my name
)</pre>
<p>print_r is a function in PHP that allows you to display the contents of an array, in key-value pairs. Here, we are printing the $_POST array. I did say these are just arrays with form data stored in them. <img src='http://www.geekscribes.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>The output therefore means:</p>
<p>Name: is the name of the field in our form. The text-box was called &#8220;name&#8221;<br />
Submit: is the name of the submit button ( Note: We can get rid of it from our array)</p>
<p>Note that &#8220;Output my name&#8221; is given as the value for submit. The value attribute of a submit input type is what&#8217;s displayed on the button in HTML.</p>
<p>Now that we know what&#8217;s stored in our POST Array, we can easily output it. We can acess it through the $_POST array. Like below:</p>
<pre>&lt;?php</pre>
<pre>  if(isset($_POST['submit']))
  {
     echo "My name is ". $_POST['name'];
  }</pre>
<pre>?&gt;</pre>
<pre>&lt;form method="post" action=""&gt;
   &lt;label for="name"&gt;Type your name&lt;/label&gt;
   &lt;input type="text" name="name" /&gt;
   &lt;input type="submit" name="submit" value="Output my name" /&gt;
&lt;/form&gt;</pre>
<p>So the code first check if the form has been submited:</p>
<pre>if(isset ($_POST['submit']) )</pre>
<p>If the array key named &#8220;submit&#8221; has a value (any value) set, then process the codes inside of the IF statement.</p>
<p>$_POST['name'], simply because, in our HTML FORM, the input where you typed your name, has the name attribute set to &#8220;name&#8221;. If you have another field, say, age. You would type $_POST['age'] to access it.</p>
<p>It&#8217;s all about arrays. You can also interact with it using a foreach loop. Most array operations in PHP could theoretically be performed on those $_GET, $_POST, &#8230; variables.</p>
<p>Now for the $_GET constant, unlike $_POST, the value is sent through the URL.</p>
<p>The form method is set to get instead of post! Try the code below, then look at your URL in the address bar</p>
<p>&lt;?php</p>
<pre>  if(isset($_GET['submit']))
  {
     echo "My name is ". $_GET['name'];
  }</pre>
<pre>?&gt;</pre>
<pre>&lt;form method="get" action=""&gt;
   &lt;label for="name"&gt;Type your name&lt;/label&gt;
   &lt;input type="text" name="name" /&gt;
   &lt;input type="submit" name="submit" value="Output my name" /&gt;
&lt;/form&gt;</pre>
<p>You will notice that your URL is now :</p>
<pre>http://localhost/test.php?<strong>name=Kevin</strong>&amp;<strong>submit=Output+my+name</strong></pre>
<pre>test.php:            This is the page we are using right now
test.php?name=kevin: This is the fun part. The ?name=&lt;name&gt;, is called a Query String, name is the $_GET Variable, and "kevin" is the value assigned to that variable.</pre>
<p>The query strings are separated from the domain by a &#8220;?&#8221; and are separated by ampersands. Spaces are substituted with &#8220;+&#8221; symbols. Note, there is a maximum length on the URL length, and hence the amount of data that can be sent via GET. So if you have to send a ton of data, use POST.</p>
<p>Another advice is don&#8217;t use multi-word names separated by spaces for the &#8220;name&#8221; attribute of fields. You don&#8217;t want to see: &#8220;?<strong>my+name</strong>=John+smith&#8221; in the URL. Then in PHP, you&#8217;d do $_POST['<strong>my_name</strong>'] as the space became an underscore. A whole lot of headaches! So don&#8217;t do it! For the sake of fellow programmers.</p>
<p>test.php?name=kevin&amp;submit=Output+my+name : the Submit is just the name of the submit button, you shouldn&#8217;t care about that too much</p>
<p><strong>IMPORTANT Notice: </strong>When using the $_GET Method, NEVER, and I mean NEVER use password field with it. Use $_POST when you form contains password field. Unless of course you want the whole world to see your password is in fact &#8220;password&#8221; :p</p>
<p>One thing you can try is, use the $_SERVER variable to check what the Actual URL Query string is set to. Try the code below:</p>
<pre>&lt;?php
if(isset($_GET['submit']))
  {
     echo "My name is ". $_GET['name'];
     echo "&lt;hr /&gt;"; //&lt;hr /&gt; just makes a horizontal rule (line) appear.
     echo "The URL Query String is ". $_SERVER['QUERY_STRING'];
     echo "&lt;hr /&gt;";
  }
?&gt;
&lt;form method="get" action=""&gt;
   &lt;label for="name"&gt;Type your name&lt;/label&gt;
   &lt;input type="text" name="name" /&gt;
   &lt;input type="submit" name="submit" value="Output my name" /&gt;
&lt;/form&gt;</pre>
<p>You will notice that the URL Query String is set to : name=&lt;name you typed&gt;&amp;submit=Output+my+name. That is, whatever comes after the &#8220;?&#8221; mark.</p>
<p>If you don&#8217;t want the &#8220;submit&#8221; part to appear in the URL, simply do not set the &#8220;name&#8221; and &#8220;value&#8221; attributes. Note, this works for GET only. If you used POST, the form doesn&#8217;t work unless &#8221; name=&#8221;submit&#8221; &#8221; is set.</p>
<p>A bonus: add this just after the last HR tag, you will see what the default $_SERVER Array holds. Code below:</p>
<pre>echo "&lt;pre&gt;";
print_r($_SERVER);
echo "&lt;/pre&gt;";</pre>
<p>You will get something like:</p>
<pre>Array
(
   [HTTP_HOST] =&gt; localhost
   [HTTP_USER_AGENT] =&gt; Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5
   [HTTP_ACCEPT] =&gt; text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
   [HTTP_ACCEPT_LANGUAGE] =&gt; en-gb,en;q=0.5
   [HTTP_ACCEPT_ENCODING] =&gt; gzip,deflate
   [HTTP_ACCEPT_CHARSET] =&gt; ISO-8859-1,utf-8;q=0.7,*;q=0.7
   [HTTP_KEEP_ALIVE] =&gt; 300
   [HTTP_CONNECTION] =&gt; keep-alive
   [HTTP_REFERER] =&gt; http://localhost/test.php?name=Kevin&amp;submit=Output+my+name

<em>   ... and it continues with other stuff.</em>
)</pre>
<p>That ton of details is a lot of details about your server and its current configuration.</p>
<p>Then you can experiment through the Array like:</p>
<pre>echo $_SERVER['HTTP_HOST'];</pre>
<p>Which will return &#8216;localhost&#8217;, as shown in the $_SERVER Global Array.</p>
<p>Ok, this should get you started.. Now let&#8217;s have a look at how we can get rid of the submit name into our $_POST Array. In order to accomplish this, we will use a built-in function of PHP. This is fun. Code below:</p>
<pre>&lt;?php

   if(isset($_POST['submit']))
   {
     // we use the array_pop function to get rid of the last element
     // In our case the last element is the submit button
     //Actually, it returns the last element of the array.
     //Since we are not capturing it, it's discarded. The array is shortened by 1 element.

     array_pop($_POST);
     echo "&lt;pre&gt;";
     print_r($_POST);
     echo "&lt;/pre&gt;";
     echo $_POST['name'];
   }
?&gt;

&lt;form method="post" action=""&gt;
   &lt;label for="name"&gt;Type your name&lt;/label&gt;
   &lt;input type="text" name="name" /&gt;
   &lt;input type="submit" name="submit" value="Output my name" /&gt;
&lt;/form&gt;</pre>
<p>Try the code, and you will see that unlike the previous one, the line &#8220;[submit] =&gt; Output my name&#8221; is gone. That&#8217;s how we get rid of it (Note: It will remove the submit button IF it is the last element in the array, if not, use an IF statement with a foreach loop to pull it out). Like below:</p>
<pre>&lt;?php</pre>
<pre>   if(isset($_POST['submit'])){</pre>
<pre>     foreach($_POST as $key =&gt; $post)
     {
        if($key != "submit")
        {
          echo $post;</pre>
<pre>        }
     }
   }</pre>
<pre>?&gt;</pre>
<pre>&lt;form method="post" action=""&gt;
   &lt;label for="name"&gt;Type your name&lt;/label&gt;
   &lt;input type="text" name="name" /&gt;
   &lt;input type="submit" name="submit" value="Output my name" /&gt;
&lt;/form&gt;</pre>
<p>If you do a print_r of $_POST, the submit will be there, because we didn&#8217;t use a function to pull it from it&#8217;s original array,but from every key and it&#8217;s value, we check if there is something which isn&#8217;t equal to &#8220;submit&#8221;, the IF statement will get rid of it, then when we echo the temporary variable $post, we get only our name.</p>
<p>Read this post again and again, until you understand how HTML Forms and PHP Works, next time there will be more from Complex Forms. Try fiddling with the $_GET and $_POST arrays and see the effects. You can also set values in $_GET and $_POST though it&#8217;s a bit useless. They are arrays after all. <img src='http://www.geekscribes.net/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<h3 style="text-align: center;">This article was contributed by Tipa of <a  title="Mu-Anime: Tipa's Site" href="http://www.mu-anime.com/" target="_blank">Mu-Anime</a></h3>

<p>This article comes from <a  href="http://www.geekscribes.net/blog">GeekScribes</a><br/><br/><a  href="http://www.geekscribes.net/blog/2009/12/10/php-lessons-8-server-constants-and-html-forms/">PHP Lessons 8: Server Constants and HTML Forms</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.geekscribes.net/blog/2009/12/10/php-lessons-8-server-constants-and-html-forms/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>PHP Lessons 7: Functions in PHP</title>
		<link>http://www.geekscribes.net/blog/2009/08/17/php-lesson-functions/</link>
		<comments>http://www.geekscribes.net/blog/2009/08/17/php-lesson-functions/#comments</comments>
		<pubDate>Mon, 17 Aug 2009 19:26:03 +0000</pubDate>
		<dc:creator>Guest-GS</dc:creator>
				<category><![CDATA[PHP Lessons]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[How To]]></category>
		<category><![CDATA[Lessons]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.geekscribes.net/blog/?p=701</guid>
		<description><![CDATA[Ok guys and girls, this is lesson 6 and I hope we can at least get to lesson 100! Today we will have a look at functions in PHP. First, what&#8217;s a function? It&#8217;s simply a sort of container for code. Whenever you call the function, the code inside gets executed. Also, functions can accept [...]<p>This article comes from <a href="http://www.geekscribes.net/blog">GeekScribes</a><br/><br/><a href="http://www.geekscribes.net/blog/2009/08/17/php-lesson-functions/">PHP Lessons 7: Functions in PHP</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Ok guys and girls, this is lesson 6 and I hope we can at least get to lesson 100! <img src='http://www.geekscribes.net/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>Today we will have a look at functions in PHP. First, what&#8217;s a function? It&#8217;s simply a sort of container for code. Whenever you call the function, the code inside gets executed. Also, functions can accept parameters, which are values that the function needs to work. If you remember a bit of your maths, &#8220;cos x&#8221; is a <em>function</em>, and x is the <em>parameter or argument</em>. Usually the result you get by doing the cosine operation is the <em>return</em> value. Just remember those terms for later.</p>
<p><span id="more-701"></span></p>
<p>PHP provides us with a lot of built-in functions which make our life easier and also speed up our projects. But sometimes, you have code you wrote and you want to be able to access those code on another pages. You would say, well, I can copy and paste the code on the supposed page or paste it whevever I need but really, this isn&#8217;t a good PHP approach, nor good programming approach in general. So, a good thing to know is that PHP allows us to write our own functions which we programmers call &#8216;User Defined Functions&#8217;.</p>
<p>First of all, I won&#8217;t be listing any built-in function in this lesson since there are tons of them. And you can&#8217;t possibly know all of them by heart nor can we list them all here. You can go to the link below and have a look at all the built-in function PHP provides. Bookmark that page, it&#8217;s great reference material.</p>
<p><a  title="PHP Function Quickref" href="http://www.php.net/quickref.php" target="_blank">PHP Function Quickref</a></p>
<p>Ok, moving on to our topic- today I will show you how you can write your own functions.</p>
<p>The syntax is like this:</p>
<pre>&lt;?php

  function function_name(){
      //put codes here
  }

?&gt;</pre>
<p>Let&#8217;s analyze this, when writing a function, you should ALWAYS start with the word &#8216;function&#8217; (without the single quotes). What comes after the word<br />
&#8220;function&#8221;, is simply the name of you function. It could be anything except Numbers and can&#8217;t contain spaces. After the name of your function, you put the brackets, then your curly braces.</p>
<p>Note: In the braces right after your function name, you can pass in arguments. We will cover those later in this lesson.</p>
<p>Instead of using function_name as the name of my function, i could have named it &#8216;geekscribes&#8217;, like below</p>
<pre>&lt;?php

  function geekscribes(){
      //put codes here
  }

?&gt;</pre>
<p>But remember to always use meaningful names for your function! This is PRIMORDIAL if you want to become a good programmer. Because nobody can guess what &#8220;function xyz()&#8221; will do, but &#8220;function avgcalc()&#8221; makes more sense. Since we are at naming functions, there are some conventions you might want to follow. No convention is forced upon you, so just choose the one you like and stick with it. And please, I mean STICK WITH IT, so don&#8217;t change along the way when you are coding. Just keep a standard.</p>
<p>Function names usually won&#8217;t have spaces. Numbers and underscores are accepted, but their usage is discouraged. Functions should be camelCased, that is the first letter of the first word lowercase, the remaining words&#8217; first letters uppercased. For e.g. &#8220;function getInput()&#8221; is appropriate. You could have written &#8220;function get_input()&#8221; too. That&#8217;s what I meant by choose a convention and stick with it. I usually use the first one, &#8220;getInput()&#8221;.</p>
<p>So, how do I use a function?</p>
<p>Below is a little example:</p>
<pre>&lt;?php

  function geekscribes(){
      echo "I'm a website";
  }

?&gt;</pre>
<p>To run this code, write it in a file, save it as &#8220;file.php&#8221; or something, it should end in &#8220;php&#8221; though. Put it in your webserver root, &#8220;www&#8221;, &#8220;public_html&#8221; or whatever, start your server and access it. Eg. &#8220;http://localhost/file.php&#8221;. Tada, blank page! Huh wait, something must be wrong? Nope, it&#8217;s totally correct. What just happened then?</p>
<p>Well, the answer to that is: When you write a function, it won&#8217;t do anything good unless you <em>call</em> the function. How do we call the function, below is an example:</p>
<pre>&lt;?php

  function geekscribes(){
      echo "I'm a website";
  }

  geekscribes(); // we call the function like this

?&gt;</pre>
<p>Run this code now, you will see &#8216;I&#8217;m a website&#8217; on your screen.  You call functions simply by writing the &#8220;function_name()&#8221; part followed by a semi-colon, in this case &#8220;geekscribes();&#8221;. Don&#8217;t put the &#8220;function&#8221; part in front. You put &#8220;function&#8221; in front when you are declaring a function, not when calling.</p>
<p>Well, this is just a basic example of function and this is actually the wrong approach of using function. Why? Because we are echoing our values directly in the function which is considered BAD practice. Well, you might say, how the hell will I get something on the screen if I don&#8217;t use the echo? Well, you can use the &#8216;return&#8217; keyword. Ok, let&#8217;s have an example below:</p>
<pre>&lt;?php

  function geekscribes(){
      return "I'm a website";
  }

  echo geekscribes(); // we call the function like this

?&gt;</pre>
<p>You echo what the function returns, i.e. it will return the string &#8220;I&#8217;m a website&#8221;. Return is like the function is sending back something to wherever it was called.</p>
<p>Always remember, do NOT echo stuff directly into your function. This is considered BAD practice. Use the word &#8216;<em>return</em>&#8216; then, just place an echo before calling your function back. Oh, not all functions return values. Some may just do some operation silently, but it&#8217;s good practice to return a value to indicate if the operation was successful or it failed. It makes checking for errors easier.</p>
<p>An important point to note: The return statement/line marks the end of the function. Whatever code you place after the return does not get executed. It&#8217;s as if, when return is encountered, the function immediately exits, returning whatever value it needs to return. This mechanism can be useful in a number of ways, e.g. checking for a range of values, and returning &#8220;false&#8221; if an input is outside the valid range, or doing some operation and returning the good result if the range was respected.</p>
<p>There are some questions you might ask. Like, &#8220;In what way will function help me?&#8221;</p>
<p>Well, assume you are working on a project with a database, you will have to connect to the database first, so instead of typing the same thing on and on, you could just wrap it in a function and call that function anytime you want to make a connection to the database and query out some stuff. In other words, it&#8217;s useful if you need to do a task several times, at different points in time. Ok, some of you might be wondering what is this &#8220;database&#8221; connection thing. Patience! It will come later in another lesson.</p>
<p>Back to our function lesson.</p>
<p>We now know how to write a function. Let&#8217;s have a look at how we can pass arguments to our function.</p>
<p>Remember I told you earlier that we can pass arguments between the braces, right after the function name? Below is an example of how it is:</p>
<pre>&lt;?php

  function geekscribes($args){
      //put codes here
  }

?&gt;</pre>
<p>As you can, the function now take one arguments. which i called $args. It&#8217;s just a variable. Nothing more. Really simple. If you want to pass in more arguments, just put a comma after the variable $args and write another variable there. Just comma-separate all the variables you want to pass in, like so:</p>
<pre>&lt;?php

  function geekscribes($args, $another_args, $yet_another_args){
      //put codes here
  }

?&gt;</pre>
<p>But for the sake of this lesson, let&#8217;s keep this simple. Let&#8217;s see how we can get the function to work with an argument.</p>
<pre>&lt;?php

  function geekscribes($msg){
      return $msg;
  }

  echo geekscribes('Hey how are you doing? Any php lesson for today?');

?&gt;</pre>
<p>Let&#8217;s break this down. Our function takes one argument, which I called $msg (it makes more sense since I&#8217;m going to output a message. Good naming practices, kids, remember!). Between my curly braces, I just wrote:</p>
<p><code>return $msg;</code></p>
<p>What it does is return whatever message I will pass to that function when calling it. As you can see in the code above, i wrote</p>
<p><code>echo geekscribes('Hey how are you doing? Any php lesson for today?');</code></p>
<p>The message &#8220;Hey how are you doing? Any php lesson for today?&#8221;, is the parameter our function will take. Remember that when passing parameter to the function, it should be between quotes. Single quotes or double quotes. Usually, we use single quotes, unless the text has apostrophes inside. Then only, use double quotes, since single quotes would mess everything up. Eg. &#8216;I&#8217;m a website&#8217;. PHP thinks that what you want to pass in is &#8220;I&#8221;, and then finds an unclosed quote after website, and it goes &#8220;WTF?&#8221; and crashes.</p>
<p>If we didn&#8217;t put something between the quotes when calling our function, we would get that error:</p>
<p><code>Warning: Missing argument 1 for geekscribes()</code></p>
<p>What it means is that PHP was expecting an argument (or more), and you didn&#8217;t supply one (or more). Poor thing was sad, and wants you to know it. Hope that makes sense!</p>
<p>Now a little technique that can be use to avoid getting such ugly error messages when calling function is like below:</p>
<pre>&lt;?php

  function geekscribes($msg=''){
    if(!$msg){
        $msg = 'This is a default text';
    }

    return $msg;
  }

  echo geekscribes().'&lt;br /&gt;';

  echo geekscribes('Hey how are you doing? Any php lesson for today?');

?&gt;</pre>
<p>As you can see, our argument $msg is a bit different. We just assigned it to nothing. Which means, it can be optional when calling our function.</p>
<p>Let&#8217;s break the code above. We start by writing our function:</p>
<pre>&lt;?php

  function geekscribes($msg=''){

  }

?&gt;</pre>
<p>In our function, we use our good if statement to check if the argument message is empty. Of course it will be empty, since we wrote $msg = &#8221;.</p>
<p>If it is empty, then we will set the $msg variable to &#8220;This is a default text&#8221;, otherwise, just return the $msg variable.</p>
<pre>&lt;?php

  function geekscribes($msg=''){

    if(!$msg){
      // if the variable $msg is empty, just give it a default text
      $msg = 'This is a default text';
    }

    //return the variable
    return $msg;

  }

  // Will output "This is a default text" since we didn't pass
  // in any message when echoing the function
  echo geekscribes().'&lt;br /&gt;';

  // Below will output "Hey how are you doing? Any php lesson for today?"
  // Since we gave it that sentence to output
  echo geekscribes('Hey how are you doing? Any php lesson for today?');
?&gt;</pre>
<p>Now, a little tip, have a look at our if statement in the function, we wrote if(!$msg). Instead of using the ! operator, let&#8217;s use a built-in function called empty(). Homework: Investigate the isset() function too. Have a look below:</p>
<pre>&lt;?php

  function geekscribes($msg=''){

    if(empty($msg)){
        // if the variable $msg is empty, just give it a default text
        $msg = 'This is a default text';
    }

    //return the variable
    return $msg;

  }

  //The line below will output "This is a default text"
  //since we didn't pass in any message when echoing the function
  echo geekscribes().'&lt;br /&gt;';

  //The line below will output "Hey how are you doing? Any php lesson for today?"
  //since we gave it that sentence to output
  echo geekscribes('Hey how are you doing? Any php lesson for today?');

?&gt;</pre>
<p>It will work fine, just as with the (!$msg) one. Just remember that you need to make sure you close your braces else you will get an ugly error. Example below:</p>
<p><code>if( empty ($msg) )</code></p>
<p>Another quick tip, remember the Ternary Operator we talked about in the Operator lesson? Let&#8217;s use this to return our variable.</p>
<pre>&lt;?php

  function geekscribes($msg=''){
      return empty($msg) ? 'This is a default text' : $msg;
  }

  echo geekscribes().'&lt;br /&gt;';

  echo geekscribes('Hey how are you doing? Any php lesson for today?');

?&gt;</pre>
<p>It basically means, if $msg is empty, return &#8216;This is a default text&#8217;, else return $msg that was passed itself.</p>
<p>Hope you get the idea. Try those on your own. If you&#8217;re stuck, comments are open below. Just drop some words and we will get to you.</p>
<h3 style="text-align: center;">This article was contributed by Tipa of <a  title="Mu-Anime: Tipa's Site" href="http://www.mu-anime.com/" target="_blank">Mu-Anime</a></h3>
<p style="text-align: left;"></p>
<p>This article comes from <a  href="http://www.geekscribes.net/blog">GeekScribes</a><br/><br/><a  href="http://www.geekscribes.net/blog/2009/08/17/php-lesson-functions/">PHP Lessons 7: Functions in PHP</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.geekscribes.net/blog/2009/08/17/php-lesson-functions/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>PHP Lessons 6: Break and Continue</title>
		<link>http://www.geekscribes.net/blog/2009/08/15/php-lessons-break-continue/</link>
		<comments>http://www.geekscribes.net/blog/2009/08/15/php-lessons-break-continue/#comments</comments>
		<pubDate>Sat, 15 Aug 2009 18:02:37 +0000</pubDate>
		<dc:creator>InF</dc:creator>
				<category><![CDATA[PHP Lessons]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[How To]]></category>
		<category><![CDATA[Lessons]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.geekscribes.net/blog/?p=694</guid>
		<description><![CDATA[Last time we saw how to work with the different kinds of loops: the While, Do While, For and Foreach loops. Today, we are going to see two keywords, &#8220;break&#8221; and &#8220;continue&#8221; that you may use to operate on loops and Switch blocks. You can consider this to be a continuation of the Loops lesson. [...]<p>This article comes from <a href="http://www.geekscribes.net/blog">GeekScribes</a><br/><br/><a href="http://www.geekscribes.net/blog/2009/08/15/php-lessons-break-continue/">PHP Lessons 6: Break and Continue</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Last time we saw how to work with the different kinds of loops: the While, Do While, For and Foreach loops. Today, we are going to see two keywords, &#8220;break&#8221; and &#8220;continue&#8221; that you may use to operate on loops and Switch blocks. You can consider this to be a continuation of the Loops lesson.</p>
<p><span id="more-694"></span></p>
<p>First, you need to know what those two do:</p>
<p>&#8220;break&#8221; &#8211; if PHP encounters this keyword in a loop, it will immediately stop the loop, and get out of the loop block, whatever the condition is, whether it is returning true or false.</p>
<p>&#8220;continue&#8221; &#8211; if PHP encounters this keyword in a loop, it will stop where it has reached in the loop body, and start another loop without processing the remaining statements.</p>
<p>Optionally, with &#8220;break&#8221; you can have a parameter that tells it how many nested structures to break out of. We&#8217;ll see about that in a moment.</p>
<p>Let&#8217;s see how we can use &#8220;break&#8221; first.</p>
<pre>&lt;?php

  $i = 0;

  while ($i &lt; 10){
      $i++;
  }

  echo "The value of i is: " . $i;
?&gt;</pre>
<p>The above code increments i up to 10 and echoes &#8220;The value of i is: 10&#8243; after it ends. It doesn&#8217;t make much sense, but it&#8217;ll be our example. If I were to use the &#8220;break&#8221; keyword, I could have written that same code as:</p>
<pre>&lt;?php

  $i = 0;

  while(true)
  {
      if ($i == 10){
          break;
      }

      $i++;
  }

  echo "The value of i is: " . $i . "&lt;br /&gt;";
?&gt;</pre>
<p>Notice above, I have intentionally created an infinite loop when I said &#8220;while (true)&#8221;. Why is it an infinite loop? Simply because the condition is always true (true is True always) so the loop never ends. I could also have written, &#8220;while(1)&#8221; for the same effect. But if we continue further, there is a condition that checks when $i gets to 10, then, we go into the body of the IF block. The overall effect is that when $i is 10, the loop will break, and we get our echo.</p>
<p>If we had to break out of a nested loops, say 2 loops, we&#8217;d do:</p>
<pre>&lt;?php

  for ($i=0; $i&lt;10; $i++){
      for ($j=0; $j&lt;5; $j++){
          //some code here

          if (some condition here){
              break 2;
          }
      }
  }

?&gt;</pre>
<p>&#8220;break&#8221; is also used in the Switch blocks, as we have seen previously, in the Conditions lesson.</p>
<p>Now, for the continue, let&#8217;s see how we can get only even numbers from 0 to 10.</p>
<pre>&lt;?php

  for ($i=1; $i&lt;=10; $i++){

      if ($i % 2 != 0){
          continue;
      }

  echo "The value of i: " . $i . "&lt;br /&gt;";

?&gt;</pre>
<p>The code above is to find the even numbers from 1 to 10. There is a For loop to do the 1 to 10 counting. The IF condition inside the loop checks whether $i has an even number inside. How? We use the modulo operator, %. The modulo operator returns the remainder of a division operation. So, if we divide an even number by 2, the remainder is zero. If it&#8217;s an odd number, the remainder would be non-zero. That&#8217;s what we use here, the non-zero value. If the value is indeed non-zero, we do the &#8220;continue;&#8221; statement. This tells PHP to stop the loop where it has reached, and resume a new loop.</p>
<p>For e.g. if $i is 3, ($i % 3) returns 1 (a non-zero value) and we go into the IF condition. The continue tells PHP to start a new loop, and $i is now 4. We have effectively skipped the echoing of 3. Just like this, we skip all the odd numbers to keep just the even ones. That&#8217;s what continue does &#8211; skipping iterations.</p>
<p>What we get as output:</p>
<pre>The value of i is: 2
The value of i is: 4
The value of i is: 6
The value of i is: 8
The value of i is: 10</pre>
<p>&#8220;continue&#8221; too has the optional parameter to tell it how many nested loops it should skip out of. Like, &#8220;continue 3;&#8221; would mean, go to the outer third loop, and restart anew there.</p>
<p>This concludes Lesson 6. In fact, this lesson should have been together with Lesson 5: Loops, but I broke it down because Loops was becoming too long.</p>

<p>This article comes from <a  href="http://www.geekscribes.net/blog">GeekScribes</a><br/><br/><a  href="http://www.geekscribes.net/blog/2009/08/15/php-lessons-break-continue/">PHP Lessons 6: Break and Continue</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.geekscribes.net/blog/2009/08/15/php-lessons-break-continue/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Lessons 5: Loops</title>
		<link>http://www.geekscribes.net/blog/2009/08/14/php-lessons-loops/</link>
		<comments>http://www.geekscribes.net/blog/2009/08/14/php-lessons-loops/#comments</comments>
		<pubDate>Fri, 14 Aug 2009 13:15:31 +0000</pubDate>
		<dc:creator>Guest-GS</dc:creator>
				<category><![CDATA[PHP Lessons]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[How To]]></category>
		<category><![CDATA[Lessons]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.geekscribes.net/blog/?p=690</guid>
		<description><![CDATA[Loooooops! In this lesson, we will have a look at the foreach function in php. First, what is a loop? I&#8217;d say something that repeats or involves a repetition can be considered a loop. In programming, you use a loop to have a bunch of codes run for a number you set. If there were [...]<p>This article comes from <a href="http://www.geekscribes.net/blog">GeekScribes</a><br/><br/><a href="http://www.geekscribes.net/blog/2009/08/14/php-lessons-loops/">PHP Lessons 5: Loops</a></p>
]]></description>
			<content:encoded><![CDATA[<p><strong>Loooooops!</strong></p>
<p>In this lesson, we will have a look at the foreach function in php.</p>
<p>First, what is a loop? I&#8217;d say something that repeats or involves a repetition can be considered a loop. In programming, you use a loop to have a bunch of codes run for a number you set. If there were no loops, you&#8217;d have to write that piece of code x times if you wanted to run it for x times, which is crazy! Read on to know the solution!</p>
<p><span id="more-690"></span></p>
<p>For example, I could tell PHP to give me 5 &#8220;Hello, World!&#8221; like this:</p>
<pre>&lt;?php

  echo "Hello, World!";
  echo "Hello, World!";
  echo "Hello, World!";
  echo "Hello, World!";
  echo "Hello, World!";

?&gt;</pre>
<p>5 is ok. What if I wanted 10,000 &#8220;Hello, Worlds&#8221;? Happy copy-pasting! But no, that&#8217;s where loops come useful. I could just tell PHP:</p>
<pre>&lt;?php

  do what follows 10,000 times:
      echo "Hello, World";

?&gt;</pre>
<p>That&#8217;s what a loop is. Well the line &#8220;do what follows&#8221; is not a PHP command! We&#8217;ll see the real syntax soon. Just remember this &#8220;Hello, World example&#8221; since we&#8217;ll use it below for illustration.</p>
<p>There are 4 types of loops which are mostly used:</p>
<p>1. The While loop<br />
2. The Do While loop<br />
3. The For loop<br />
4. The Foreach loop</p>
<p><strong>The While loop</strong></p>
<p>Let&#8217;s see how we could do 5 Hello World with a While loop:</p>
<pre>&lt;?php

  $i = 0; //initializing our counter

  while ($i &lt; 5){

      echo "Hello, World";

      $i++; //Incrementing count
  }

?&gt;</pre>
<p>Not that tough is it? And definitely much smaller than the one above. For 10,000? Just replace: while ($i &lt; 10000). The rest is the same. It&#8217;ll run for 10,000 times! That&#8217;s how you do a While loop. Let&#8217;s analyse the code.</p>
<p>Loops need a counter variable, which we programmers like naming i, j, x, y or your favourite single letter. Usually, we start at i and move on. i is like a non-standard convention that programmers use, which says that the var is a loop counter.</p>
<p>Then, we do the While part. Notice that I used $i &lt; 5 and not $i &lt;= 5. It&#8217;s so because I started the count at zero, which is the usual way. If you start the counter at one, then it will be $i &lt;= 5; But start with zero. It&#8217;s more often used. So, $i &lt; 5. The While loop will check the value of $i everytime the loop runs. It&#8217;d go like this:</p>
<pre>Value of $i is less than 5? ($i = 0) Yep, so run loop. Increment $i. ($i = 1)
Value of $i is less than 5? ($i = 1) Yes, so run loop. Increment $i. ($i = 2)
Value of $i is less than 5? ($i = 2) Ya,  so run loop. Increment $i. ($i = 3)
Value of $i is less than 5? ($i = 3) Yay, so run loop. Increment $i. ($i = 4)
Value of $i is less than 5? ($i = 4) Yey, so run loop. Increment $i. ($i = 5)
Value of $i is less than 5? ($i = 5) NO! ($i &lt; 5) returns false. End the loop!</pre>
<p>So you see the loop made 5 runs.</p>
<p>For a While loop, you should absolutely NOT FORGET the Increment Your Count part. This is vital! What happens if you miss that line? You get an Infinite Loop, or a loop that never ends. Or simply, an awful massively huge lot of &#8220;Hello, World!&#8221; and your code crashes.</p>
<p><strong>The Do While loop</strong></p>
<p>The Do While loop is just a reverse While. If you read the code from the previous section carefully, you will see that the While loop makes the variable /counter check at the start of the loop. In a Do While loop, we make the check AFTER the loop.</p>
<p>What does this change? The While loop code above wouldn&#8217;t run if I had initialized the counter to $i = 10; PHP would just have skipped the loop and process the code after it if any, since $i is not less than 5.</p>
<p>But if I had done it with the Do While loop:</p>
<pre>&lt;?php

  $i = 0; //initializing our counter

  do{
      echo "Hello, World";

      $i++; //Incrementing count

  }while ($i &lt; 5);
?&gt;</pre>
<p>That code would have ran for at LEAST one time, so even if I had initialized $i = 10; there would be ONE &#8220;Hello, World&#8221; that gets output. Of course, if $i is zero at the start, you&#8217;d get your 5 &#8220;Hello, World&#8221; normally, as the While loop.</p>
<p>So how is this change useful? In some situations, you might want to run a check, then decide to see how many times to run the loop, if ever you want to run it. It is in those situations that the Do While is important.</p>
<p>Important thing to notice is the structure of the Do While loop itself. There is NO semicolon after the &#8220;do&#8221; keyword. The semicolon comes AFTER the &#8220;while ($i &lt; 5)&#8221; condition check. Again, don&#8217;t miss that semicolon (or any of them, for that matter). Your code won&#8217;t run.</p>
<p><strong>The For Loop</strong></p>
<p>The For Loop is just like a classic While loop, but it includes the initialization, check and incrementation/decrementation directly in its declaration. Yep, you might want to decrement a count instead of incrementing it. Why? That&#8217;s what you&#8217;d do if you wanted to echo something in reverse. Start the counter at the last position, and decrement to the start.</p>
<p>Back to the For loop:</p>
<pre>&lt;?php

  for ($i=0; $i&lt;5; $i++){

      echo "Hello, World";
  }
?&gt;</pre>
<p>That&#8217;s how your For loop looks like, and it will give you your 5 &#8220;Hello, World&#8221; as above. You can notice how concise it is. Let&#8217;s analyse it.</p>
<p>for ($i=0; $i&lt;5; $i++) The first part/parameter is the initialization. Next comes the condition. Finally the incrementing. Note those semicolons. They are NOT commas. This is a common mistake among beginners.</p>
<p><strong>The Foreach loop</strong></p>
<p>The Foreach loop is specially designed to work with Arrays (read our lesson on Arrays if you haven&#8217;t done so yet). As you probably know by now, Arrays are just consecutive storage spaces, like a set of variables. Sometimes, you might want to do something about all the data in the array, like echoing the data in each slot. Or maybe, some selective slot? Maybe check for some value? All those are done via the Foreach loop.</p>
<p>Basically, the Foreach is in fact &#8220;foreach slot in an array, do those codes&#8221;. The Foreach loop in PHP4 works ONLY on arrays by the way. PHP5 can iterate over visible values in classes too. Classes and Object-Oriented Programming come further away in the series.</p>
<p>An example, this time coming from the Arrays lesson. To output the values we have, we would just echo $name[0],$name[1] and so on.</p>
<pre>&lt;?php

  $persons = array('John','Richard','Max','Michael');

  echo $name[0]; // outputs john
  echo $name[1]; // outputs Richard
  echo $name[2]; // outputs Max
  echo $name[3]; // outputs Michael

?&gt;</pre>
<p>But, what if the data are coming from a database and you have around 100 values? WTF, does that mean we should keep echoing $name[0] to $name[99]? No way, that&#8217;s pointless and it will tax the server. So, the Foreach loop will come in handy in this kind of situation.</p>
<p>How do we write a foreach? Below is the general syntax:</p>
<pre>&lt;?php

  foreach($our_array as $the_value){

      //keep doing what you're told to with the values

  }

?&gt;</pre>
<p>Let&#8217;s iterate through our arrays with the foreach loop:</p>
<pre>&lt;?php

  $persons = array('John','Richard','Max','Michael');

  foreach($persons as $value){

      echo $value.'&lt;br /&gt;';

  }

?&gt;</pre>
<p>What it means in the code above is, foreach item in the array (the array is $persons), copy it to the $value variable, then between the curly braces, output every value you got. The output will be like this:</p>
<p>John<br />
Richard<br />
Max<br />
Michael</p>
<p>As you can see, with this simple foreach, we were able to output the four names in our array without having to echo every items in the array. That&#8217;s much better and also, this simple code will also output 100 values if they were in the array.</p>
<p>A little note: Some of you might be wandering why is there a &#8216;&lt;br /&gt;&#8217; at the end. If you know some HTML (Which I suppose you know a bit of. To really use PHP well, you need to have a basic HTML knowledge), then the &lt;br /&gt; tag will simply insert a simple break line. What I did in the code above is simply concatenated the HTML BR (BReak) tag to the end of the variable by using the period sign (the dot if you prefer), and then adding the &lt;br /&gt; tag between single quotes and end the statement with the semicolon.</p>
<p>Ok, this give us an idea our the foreach loop, but what if my array contains a KEY for every VALUE, as in Associative Arrays? The answer is: You can still use the foreach loop to get the both the KEY and the VALUE in your array. The  general syntax is below:</p>
<pre>  foreach($our_array as $the_key =&gt; $the_value){
      //do your stuff here
  }</pre>
<p>Have a look at &#8220;the_key =&gt; the_value&#8221; . It looks the same way we write our associative array like below. &#8216;John&#8217; =&gt; &#8217;18&#8242;, John is the Key, 18 is the Value. Let&#8217;s use the foreach with it.</p>
<pre>&lt;?php

  $persons = array('John' =&gt; '18',
                   'Richard' =&gt; '20',
                   'Max' =&gt; '25',
                   'Michael' =&gt; '30'
                  );

  foreach($persons as $key =&gt; $value){
      echo $key.': ' .$value. '&lt;br /&gt;'
  }

?&gt;</pre>
<p>So remember, John, Richard, Max and Michael are Ks. We assign the Kry to the variable $key and the value to the variable $value. So you basically get an idea of how the output will be. It will be like below&#8221;</p>
<p>John: 18<br />
Richard: 20<br />
Max: 25<br />
Michael: 30</p>
<p>So if you want to make a sentence with it. say: John is 18 years old. You would do like so:</p>
<pre>&lt;?php

  $persons = array('John' =&gt; '18',
                   'Richard' =&gt; '20',
                   'Max' =&gt; '25',
                   'Michael' =&gt; '30'
                  );

  foreach($persons as $key =&gt; $value){
      echo $key.' is ' .$value. ' years old.&lt;br /&gt;';
  }

?&gt;</pre>
<p>This will output:</p>
<p>John is 18 years old.<br />
Richard is 20 years old.<br />
Max is 25 years old.<br />
Michael is 30 years old.</p>
<p>See those concatenations? That&#8217;s how we add static stuff and variables together. Add necessary spaces inside quotes too, else you will just have a bunch of unreadable lines like &#8220;Johnis18yearsold.&#8221;</p>
<p>You see how the foreach loop makes life easier. Instead of having to echo those one by one, we were able to do it with three lines of code.</p>
<p>Let&#8217;s see another example, using a For loop and a Foreach loop to do the same job.</p>
<p>Using a For loop first:</p>
<pre>&lt;?php

  $persons = array(array('name' =&gt; 'John', 'gender' =&gt; 'male'),
                   array('name' =&gt; 'Anna', 'gender' =&gt; 'female')
                  );

  for($i=0; $i&lt;count($persons); $i++){
      echo $persons[$i]['name'].'&lt;br /&gt;';
  }

?&gt;</pre>
<p>Like you see in the code above, we have our Multidimensional Array. Our For loop is pretty much the same except that you can see a little built-in function called count. What this function does, it calculate the size of the array everytime it runs through. We&#8217;ll see about Functions in a future lesson. Note, you may also see code which uses sizeof function like: $i &lt; sizeof($persons). Don&#8217;t worry, sizeof and count are the same thing. sizeof is an alias of count. Also, if you wanted to know how the length (or number of elements) a Multidimensional array contains, you can use: count ($persons, COUNT_RECURSIVE) function. COUNT_RECURSIVE is a constant with value 1, and is an optional parameter.</p>
<p>When echoing out, we use the $persons variable, we use [$i] ($i would just contain the Numeric Value of our array. Remember from the array lessons? The Numeric Array?). After passing in $i, we pass in the KEY, which is &#8216;name&#8217;! So if we didn&#8217;t use the For loop, we would have to echo our values like below:</p>
<p>echo $persons[0]['name']; // will write John<br />
echo $persons[1]['name']; // will write Max</p>
<p>Why didn&#8217;t we just write $persons['name'] ? Simply because we are using a MultiDimensional Array and we have to get to the first array inside of that Main/Parent array and so on. When using the For loop, we don&#8217;t have to specify the number &#8217;0&#8242; and &#8217;1&#8242;, since it is stored in $i which makes our work easier by echoing using only one line of code, and it would echo every name we have in the array. Very nice for large arrays.</p>
<p>Let&#8217;s see how we can do it with a Foreach loop. If you prefer to use the foreach loop to iterate through this example, it would look a bit different from what we wrote before. We would have to use our Foreach to loop in the main Array, then use another Foreach loop to get the arrays inside. This is called Nested Foreach Loop. Here&#8217;s an example below:</p>
<pre>&lt;?php

$persons = array(array('name' =&gt; 'John'),
                 array('name' =&gt; 'Max')
                );

  foreach($persons as $value){
      foreach($value as $values){

          echo $values.'&lt;br /&gt;';

      }

  }

?&gt;</pre>
<p>I know this can confuse you, but really, it&#8217;s quite simple. Let&#8217;s break it down. Have a look at our array, it contains two arrays, one in another.</p>
<p>Our first foreach will iterate through the Main array and gives us the arrays we have inside and store them in the variable $value. (we are still in the first Foreach loop &#8211; the &#8220;outer&#8221; one).</p>
<p>Since the variable $value contains the two arrays inside the main one, we have to use another Foreach loop to iterate through those arrays.</p>
<p>So our second Foreach loop (&#8220;inner&#8221; one), which is inside the first foreach loop, will take the variable $value which contains the two arrays, copy it to the variable $values in each loop, then we can start outputting the name we have inside of it.</p>
<p>Still confused? You almost should be, if you are a beginner. Just try to re-read and understand. If you have questions, use the comments form below. We try to answer questions, but are not pro&#8217;s, so we might not know everything.</p>
<p>Hopefully, by now, you understand how to use Array, how to iterate through them using either foreach and for loop.. Understand how to use a Foreach loop and how to use a For loop. Using those will make your life easier trust me. Why bother with 4 kinds of loops? Each has its use, but in most situations, the For and Foreach loops are the one you&#8217;d want. While loop is specially useful where you don&#8217;t know exactly how many times to loop or need to do something special, instead of blindly incrementing the count. More of this to come soon. <img src='http://www.geekscribes.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Try to see what those functions do on your own and how to use them:</p>
<p>is_array() &#8211; checks to see if a variable is an array<br />
in_array() &#8211; checks to see if a value is found in an array<br />
explode()  &#8211; turns a string, separated by delimiters into an array<br />
implode()  &#8211; reverse of explode. Array to string this time</p>
<p>You might want to have a look at those since later we will be using them in a tutorial where data will be coming from a MySQL database.</p>
<p>Also, remember to install WAMP or XAMP and try out those simple example for yourself just to adapt yourself with the syntax. Practice is better than just reading and trying to understand what&#8217;s happening. And if you see any syntax errors or whatever, let us know. Thanks!</p>
<p>P.S: If I&#8217;m not mistaken, I believe till now this is the longest tutorial I wrote. <img src='http://www.geekscribes.net/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<h3 style="text-align: center;">This article was contributed by Tipa of <a  title="Mu-Anime: Tipa's Site" href="http://www.mu-anime.com/" target="_blank">Mu-Anime</a></h3>

<p>This article comes from <a  href="http://www.geekscribes.net/blog">GeekScribes</a><br/><br/><a  href="http://www.geekscribes.net/blog/2009/08/14/php-lessons-loops/">PHP Lessons 5: Loops</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.geekscribes.net/blog/2009/08/14/php-lessons-loops/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

