<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-4889431653894848295</id><updated>2011-04-21T19:53:12.363-07:00</updated><title type='text'>php</title><subtitle type='html'>Beginning PHP</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://domyat.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4889431653894848295/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://domyat.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>elawael</name><uri>http://www.blogger.com/profile/11684828293686686914</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>24</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4889431653894848295.post-8839036008141335656</id><published>2008-04-01T03:00:00.000-07:00</published><updated>2008-04-01T03:03:20.437-07:00</updated><title type='text'>PHP and HTML</title><content type='html'>&lt;p&gt;Now let see how we blend PHP and HTML together.&lt;/p&gt; 			 &lt;pre class="code"&gt;&lt;html&gt;&lt;br /&gt;	&lt;title&gt;my php page&lt;/title&gt;&lt;br /&gt;	&lt;body&gt;&lt;br /&gt;	&lt;?php&lt;br /&gt;		echo "hello there!";&lt;br /&gt;	?&gt;&lt;br /&gt;	&lt;/body&gt;&lt;br /&gt;&lt;/html&gt;&lt;br /&gt;&lt;/pre&gt; 			 			&lt;p&gt;&lt;span style="color:red;"&gt;Echo&lt;/span&gt; is a special statement in php for outputing data to the browser. This statement is more often used when we need to print something to the browser. You will learn how to use echo in as we go along.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;ol&gt;&lt;li&gt;Open up notepad.&lt;/li&gt;&lt;li&gt;Copy paste the above PHP and HTML code in notepad.&lt;/li&gt;&lt;li&gt;Now, lets save the file in our www folder, i.e. c:/wamp/www&lt;/li&gt;&lt;div class="note"&gt; 					Remember, we need PHP to run PHP pages on our computer. To install PHP, please go to the &lt;a href="http://www.php-learn-it.com/php_installation.html"&gt;PHP installation page.&lt;/a&gt; 				&lt;/div&gt;&lt;li&gt;Name the file my_php_page.php and save it in your www folder.&lt;/li&gt;&lt;div class="note"&gt; All PHP files must be saved with extension .php. This is important because we need to tell the browser that we are working with PHP. &lt;/div&gt;&lt;li&gt;Now, go to &lt;a href="http://localhost/my_php_page.php"&gt;http://localhost/my_php_page.php&lt;/a&gt; in your web browser.&lt;/li&gt;&lt;/ol&gt; 				&lt;p&gt;You should see "hello there!" printed out on the browser. Pretty simple, eh?&lt;/p&gt; 				&lt;p&gt;There you have it. You first web page in PHP. Now, let’s play around with the code. Let’s do some more cool stuff.&lt;/p&gt; 			 			 			&lt;h3 id="s4"&gt;&lt;p&gt;Doing Cool Stuff with PHP and HTML&lt;/p&gt;&lt;/h3&gt; 			&lt;p&gt; Echo statement is powerful in a sence that you can put HTML code in it and it will render the text as if it was HTML in your browser. Try it! &lt;/p&gt; 			&lt;h4&gt;&lt;p&gt;Example - Make Text Bold&lt;/p&gt;&lt;/h4&gt;  			&lt;p&gt;Replace the PHP line in your code to the following code. Save the file and now refresh your page.&lt;/p&gt; &lt;pre class="code"&gt;&lt;?php&lt;br /&gt;	echo "&lt;b&gt;hello there!&lt;/b&gt;";&lt;br /&gt;?&gt;&gt;&lt;br /&gt;&lt;/pre&gt; 			&lt;p&gt;You should see &lt;b&gt;hello there!&lt;/b&gt; in bold letters in your browser. 			&lt;/p&gt; 		 		&lt;h4&gt;&lt;p&gt;Example - Make Text Green&lt;/p&gt;&lt;/h4&gt; 			&lt;p&gt;Replace the PHP line in your code to the following code. Save the file and now refresh your page.&lt;/p&gt; &lt;pre class="code"&gt;&lt;?php&lt;br /&gt;	echo "&lt;span style="color:'green';"&gt;hello there!&lt;/span&gt;";&lt;br /&gt;?&gt;&gt;&lt;br /&gt;&lt;/pre&gt; 		&lt;p&gt;You should see &lt;span style="color:green;"&gt;hello there!&lt;/span&gt; in green in your browser. 		&lt;/p&gt;  		&lt;h4&gt;&lt;p&gt;Example - What's today's date?&lt;/p&gt;&lt;/h4&gt; 			&lt;p&gt;Lets print out today's date using the php date function. Don't worry we will see more examples of the date function in later tutorials. We will learn some useful techniques for printing date in different formats. For now, let's try the following code.&lt;/p&gt; &lt;pre class="code"&gt;&lt;?php&lt;br /&gt;	echo "today is ".date('Y-m-d');&lt;br /&gt;?&gt;&lt;br /&gt;&lt;/pre&gt;   		&lt;p&gt;Try it! Replace previous echo line with this line. You should see today's date, "today is 2008-04-01", printed out on your browser. &lt;/p&gt; 		 		&lt;p&gt;So, in this section we saw how we can add PHP into our HTML code. This should give you a brief glimpse into how PHP works and what we can do with it. You're now ready to move on to some advance PHP stuff! What are we waiting for, let’s go!&lt;/p&gt; 		 		&lt;p&gt; 			&lt;/p&gt;&lt;p id="ad_box"&gt; 		Are you still stuck using HTML?&lt;br /&gt;&lt;i&gt;&lt;a style="font-size: 20px;" href="http://www.php-learn-it.com/helper_scripts/jump_to.php?goto=phpmysqlbooksales" rel="nofollow"&gt;"Learn how to build websites using PHP and MYSQL"&lt;/a&gt;&lt;/i&gt; 	&lt;/p&gt; 			 			 			&lt;div class="note"&gt; 				&lt;b&gt;Note:&lt;/b&gt; Note that, at the end of each PHP statement we need need to put a semicolon, i.e. "&lt;b&gt;;&lt;/b&gt;" as you see in the above code. Otherwise PHP will report &lt;b&gt;syntax error&lt;/b&gt;. 			&lt;/div&gt; 			 			  			&lt;p&gt;Pretty neat, eh? I remember when i first wrote my php code, i was just so amazed :)&lt;br /&gt;So, let do that. Lets write our first PHP page.  			&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4889431653894848295-8839036008141335656?l=domyat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://domyat.blogspot.com/feeds/8839036008141335656/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4889431653894848295&amp;postID=8839036008141335656' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4889431653894848295/posts/default/8839036008141335656'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4889431653894848295/posts/default/8839036008141335656'/><link rel='alternate' type='text/html' href='http://domyat.blogspot.com/2008/04/php-and-html.html' title='PHP and HTML'/><author><name>elawael</name><uri>http://www.blogger.com/profile/11684828293686686914</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4889431653894848295.post-6131616698779441145</id><published>2008-04-01T02:58:00.001-07:00</published><updated>2008-04-01T02:59:40.632-07:00</updated><title type='text'>Learn PHP and MySQL fast!</title><content type='html'>&lt;div style="text-align: center; font-weight: bold;"&gt;&lt;a href="http://www.php-learn-it.com/helper_scripts/jump_to.php?goto=phpmysqlbook" target="_blank" rel="nofollow"&gt;&lt;img src="http://www.php-learn-it.com/images/phpmysql.jpg" border="0" /&gt;&lt;/a&gt;       &lt;br /&gt;&lt;/div&gt;&lt;span style="font-weight: bold;"&gt;Learn how you can start building rich interactive database driven sites like a professional developer easily and quickly...&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;  &lt;div style="text-align: center;"&gt;&lt;a href="http://www.php-learn-it.com/helper_scripts/jump_to.php?goto=phpmysqlbook" rel="nofollow"&gt;&lt;b&gt; &gt;&gt; Order your copy now for just $39.95 &lt;&lt;&lt;/b&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;PHP sits between your browser and the web server. When you type in the URL of a PHP website in your browser, your browser sends out a request to the web server. The web server then calls the PHP script on that page. The PHP module executes the script, which then sends out the result in the form of HTML back to your browser, which you see on the screen. Here is a diagram which illustrate the process.&lt;/p&gt;   &lt;div align="center"&gt;&lt;img src="http://www.php-learn-it.com/images/php_process.jpg" alt="php process" /&gt;&lt;br /&gt;&lt;i&gt;PHP Process Diagram&lt;/i&gt;&lt;/div&gt;           &lt;h3 id="s3"&gt;&lt;p&gt;What are PHP benefits?&lt;/p&gt;&lt;/h3&gt;  &lt;p&gt;PHP is a free open source language. That means you don't have to pay thousands of dollars in licensing fee to acquire PHP. Best of all, it is easy to install. The most striking feature of it is that it is easy to learn. PHP is used by millions of people and developers around the world. There are thousands of websites on the internet which are written using PHP. One primary example is Yahoo! Bookmarks. PHP has an ever growing community. There are thousands of websites, forums and community websites dedicated on PHP. I built this site to share my PHP examples, recourses and code with you that you can use on your website easily. I will also show you how to build your own PHP website with all the bells and whistles from ground up. You will also learn the fundamentals of PHP and write your own PHP code.&lt;/p&gt;        &lt;h3 id="s4"&gt;&lt;p&gt;What I need in order to build PHP driven sites?&lt;/p&gt;&lt;/h3&gt;         &lt;h5 id="s4.1"&gt;&lt;p&gt;You need PHP Hosting&lt;/p&gt;&lt;/h5&gt;    &lt;p&gt;You need &lt;a href="http://www.php-learn-it.com/netfirms.com" target="_blank"&gt;PHP and MySQl hosting&lt;/a&gt;&lt;img src="http://www.ftjcfx.com/image-2443267-10398445" border="0" height="1" width="1" /&gt;. Good news is, you can find an affordable php and mysql host on the web anywhere. There are tons of web hosting companies trying to compete for your business.&lt;/p&gt;         &lt;p&gt;I recommend &lt;a href="http://www.php-learn-it.com/netfirms.com" target="_blank"&gt;Netfirms Hosting&lt;/a&gt;&lt;img src="http://www.ftjcfx.com/image-2443267-10398445" border="0" height="1" width="1" /&gt;. For just &lt;a href="http://www.php-learn-it.com/netfirms.com" target="_blank"&gt;$9.95/mo&lt;/a&gt;&lt;img src="http://www.ftjcfx.com/image-2443267-10398445" border="0" height="1" width="1" /&gt;, you get &lt;b&gt;PHP4 and PHP5 support&lt;/b&gt;, &lt;b&gt;30 MySQL Databases&lt;/b&gt;, &lt;b&gt;250GB of web space&lt;/b&gt; to store your files, videos and images, &lt;b&gt;2000GB of Data Transfer (plenty for even high traffic websites)&lt;/b&gt;, &lt;b&gt;2 FREE Domains&lt;/b&gt;,  and you can &lt;b&gt;HOST UNLIMITED WEBSITES&lt;/b&gt; on the same account and best of all the BEST and QUICKEST customer support I have seen.&lt;/p&gt;         &lt;br /&gt;&lt;p&gt;I recommend &lt;a href="http://www.php-learn-it.com/netfirms.com" target="_blank"&gt;Netfirms&lt;/a&gt; because I use Netfirms hosting myself and have no complaints. This is the best hosting I have used so far. They also have a $4.95 plan called the PLUS hosting plan. Just &lt;a href="http://www.php-learn-it.com/netfirms.com" target="_blank"&gt;go here&lt;/a&gt;&lt;img src="http://www.ftjcfx.com/image-2443267-10398445" border="0" height="1" width="1" /&gt; and click on their specifications or &lt;a href="http://www.php-learn-it.com/articles/shared_web_hosting.html"&gt;read the review here&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4889431653894848295-6131616698779441145?l=domyat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://domyat.blogspot.com/feeds/6131616698779441145/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4889431653894848295&amp;postID=6131616698779441145' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4889431653894848295/posts/default/6131616698779441145'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4889431653894848295/posts/default/6131616698779441145'/><link rel='alternate' type='text/html' href='http://domyat.blogspot.com/2008/04/learn-php-and-mysql-fast.html' title='Learn PHP and MySQL fast!'/><author><name>elawael</name><uri>http://www.blogger.com/profile/11684828293686686914</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4889431653894848295.post-7355627829765160572</id><published>2008-03-31T08:36:00.000-07:00</published><updated>2008-03-31T08:38:19.964-07:00</updated><title type='text'>Lesson 22 - Starting off with Databases</title><content type='html'>&lt;span class="postbody"&gt;Now is the time you have all been waiting for! Lets get into Databases!&lt;br /&gt;However, before we can start programming - I want to teach you how to &lt;span style="font-style: italic;"&gt;think&lt;/span&gt; in databases.&lt;br /&gt;&lt;br /&gt;A database (or 'DB' as they're sometimes called) is basically like a large file cabinet for different folders. Here is what a DB would look like as a picture:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;img src="http://www.learnphpfree.com/lessonfiles/database_image_1.jpg" border="0" /&gt;&lt;br /&gt;&lt;br /&gt;The Database is called &lt;span style="font-weight: bold;"&gt;database_1&lt;/span&gt; and inside the database are two tables "contacts" and "orders". Both of those tables have 3 columns in them: &lt;br /&gt;The table "orders" has the columns "id", "date", and "item".&lt;br /&gt;The table "contacts" has the columns "name", "phone", and "address".&lt;br /&gt;&lt;br /&gt;In the end, all of the information in a database is stored in one column or another; the whole point of tables is just to help group columns that have similar or related information.&lt;br /&gt;&lt;br /&gt;After each of the columns that will be in a table are made, you start getting into rows. (Think of an Excel Spreadsheet made up of rows and columns, or for those of you who have done HTML; think of &lt;table&gt;). Each row of a table will have the information for that tables columns. For example, row 1 has the information "Bob" for the column "name", "#" for the column "phone", and "TX" for the column "address". Each new record (row) in the table will have the information for that tables columns.&lt;br /&gt;&lt;br /&gt;Note: Database's can have hundreds of tables or just one. Likewise, a table can have hundreds of columns or just one. Also, all of the different tables in a DB can have different numbers of columns; just because both of the tables in this example have 3 columns doesn't mean that they have to have the same number.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;All of the interaction with a MySQL database will be done through something called a "query". A query is just another way of saying a &lt;span style="font-style: italic;"&gt;request&lt;/span&gt; for something. So next time you hear someone say "run a query on your database" you will know that they just mean give your DB a request (ask for some information from it).&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Now then, let me explain the different commands you can use on a database:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;-----------------------------------------------------------&lt;br /&gt;-- Selecting Data:&lt;br /&gt;-----------------------------------------------------------&lt;/span&gt;&lt;br /&gt;The SELECT command &lt;span style="font-style: italic;"&gt;selects&lt;/span&gt; the data that you want from a table or column. It is the most used MySQL command there is. You can optionally add a 'WHERE' command that tells the computer that you only want the data from &lt;span style="font-style: italic;"&gt;where&lt;/span&gt; you say.&lt;br /&gt;&lt;br /&gt;SELECT [columns] FROM [table] WHERE [specification];&lt;br /&gt;&lt;br /&gt;For example:&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;SELECT * FROM&lt;/span&gt; `orders` &lt;span style="font-weight: bold;"&gt;WHERE&lt;/span&gt; `ID` = 1;&lt;br /&gt;&lt;br /&gt;In English this would be:&lt;br /&gt;Select &lt;span style="font-weight: bold;"&gt;everything&lt;/span&gt; FROM a table named "orders" WHERE A Column named "ID" is equal to '1';&lt;br /&gt;&lt;br /&gt;On the example DB above this would return the values "1", "6/06", and "car". Because this is all of the information in the row of the table "orders" that has an ID equal to "1".&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Another example is:&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;SELECT&lt;/span&gt; `phone`,`name`,`address` &lt;span style="font-weight: bold;"&gt;FROM&lt;/span&gt; `contacts`;&lt;br /&gt;&lt;br /&gt;This would &lt;span style="font-style: italic;"&gt;select&lt;/span&gt; all of the information in the columns named "phone", "name", and "address" from the table named "contacts". It would return all of the data based on the rows that the data was in. For example, the result of this command on the above database would return an array with each element a row from the table:&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;  	  &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt; 	&lt;/tr&gt; 	&lt;tr&gt; 	  &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;7&lt;br/&gt;8&lt;br/&gt;9&lt;br/&gt;10&lt;br/&gt;11&lt;br/&gt;12&lt;br/&gt;13&lt;br/&gt;14&lt;br/&gt;15&lt;br/&gt;&lt;/td&gt; --&gt; 	  &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;br /&gt;$result&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'1'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;][&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'name'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;would be equal to &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Bob"&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$result&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'1'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;][&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'phone'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;would be equal to &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"#"&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$result&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'1'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;][&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'address'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;would be equal to &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"TX"&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$result&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'2'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;][&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'name'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;would be equal to &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Sam"&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$result&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'2'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;][&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'phone'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;would be equal to &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"#"&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$result&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'2'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;][&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'address'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;would be equal to &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"CA"&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$result&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'3'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;][&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'name'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;would be equal to &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Joe"&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$result&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'3'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;][&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'phone'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;would be equal to &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"#"&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$result&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'3'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;][&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'address'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;would be equal to &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"FL"&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt; 	&lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;There are &lt;span style="font-style: italic;"&gt;three&lt;/span&gt; elements in the array $result because there are three rows in the table "contacts".&lt;br /&gt;Then there are &lt;span style="font-style: italic;"&gt;three&lt;/span&gt; sub-elements in each of the array's elements because there are three columns for each row.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Have I lost you yet? Actually, this might be a little bit much if you are new to this kind of thing. So just try to understand as much as you can and just come back after we have done a little with DB's.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;-----------------------------------------------------------&lt;br /&gt;-- Creating Data:&lt;br /&gt;-----------------------------------------------------------&lt;/span&gt;&lt;br /&gt;Second you need to know how to &lt;span style="font-style: italic;"&gt;INSERT&lt;/span&gt; data into the DB. &lt;br /&gt;Inserting data is how you get data &lt;span style="font-style: italic;"&gt;into&lt;/span&gt; the database.&lt;br /&gt;&lt;br /&gt;The syntax for inserting information is:&lt;br /&gt;INSERT INTO `tablename` ( `columne_1` , `columne_2` ) VALUES ('valueforcolumn_1', 'valueforcolumn_2');&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Example Query:&lt;br /&gt;INSERT INTO `contacts` ( `name` , `phone` , `address` ) VALUES ('Bob', '#', 'TX');&lt;br /&gt;&lt;br /&gt;If I ran this code on the database above it would make the information in row "1".&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Now then, enough of this - lets make something! &lt;img src="http://www.learnphpfree.com/images/smiles/tongue.gif" alt=":P" border="0" /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;-----------------------------------------------------------&lt;br /&gt;-- Making Your First Database:&lt;br /&gt;-----------------------------------------------------------&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;For this next project you will need to know what your database username and password is, and what the database server name ("host") is. If you don't have access to some kind of control panel where you can find out (like cPanel or 1and1's MySQL Administration) you need to call your web host and ask them for this information. If you don't have a database on your web host you are being ripped-off. In our day and age they are given out like candy so there is no reason for your host not to give you one! (If you need a new host I recommend &lt;a href="http://www.1and1.com/?k_id=8532941" target="_blank" class="postlink"&gt;1and1.com&lt;/a&gt;, or if you are out-side of the USA I recommend &lt;a href="http://www.bluehost.com/track/weblistings/lpf" target="_blank" class="postlink"&gt;Bluehost.com&lt;/a&gt;)&lt;br /&gt;&lt;br /&gt;Also, you need your database to be a "MySQL" database. This script will not work on PostSQL, Oracle, SQL, or the like.&lt;br /&gt;&lt;br /&gt;If you have easyPHP, WAMP, AMP, or some other kind of server on your &lt;span style="font-style: italic;"&gt;own&lt;/span&gt; PC then your username is probably "root", your password is "" (nothing), and your host will be "localhost".&lt;br /&gt;&lt;br /&gt;Open up SciTE (in our downloads section) and type this into it:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;  	  &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt; 	&lt;/tr&gt; 	&lt;tr&gt; 	  &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;7&lt;br/&gt;8&lt;br/&gt;9&lt;br/&gt;10&lt;br/&gt;11&lt;br/&gt;12&lt;br/&gt;13&lt;br/&gt;14&lt;br/&gt;15&lt;br/&gt;16&lt;br/&gt;17&lt;br/&gt;18&lt;br/&gt;19&lt;br/&gt;20&lt;br/&gt;21&lt;br/&gt;22&lt;br/&gt;23&lt;br/&gt;24&lt;br/&gt;25&lt;br/&gt;&lt;/td&gt; --&gt; 	  &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Create the database access variables:&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$hostname &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"localhost"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$database &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"testdatabase"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$username &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"root"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$password &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;""&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Open a connection to the server&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$connection &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;mysql_connect&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$hostname&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$username&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$password&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) &lt;br /&gt;or die (&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Unable to connect to the DB Server!"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Make the query we wan to use&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$query &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'CREATE DATABASE '&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;. &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$database&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;. &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;';'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Now lets make a Database&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$result &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;mysql_query&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$query&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) or die (&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Error in query: $query. &lt;br /&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;.&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;mysql_error&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;());&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Made Database $database"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt; 	&lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;Save it as "makedb.php" and upload it to your server. &lt;br /&gt;&lt;br /&gt;If you have the "RIGHTS" to make a Database it should run just fine. If not you need to make sure and check that you entered the right variables, then call your host to see if you have the "RIGHTS" to make a Database. If you still can't get this to work just post a request for help in the MySQL forum.&lt;br /&gt;&lt;br /&gt;If you try to run this script a second time you will see the error:&lt;br /&gt;&lt;/span&gt;&lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="90%"&gt;&lt;tbody&gt;&lt;tr&gt; 	  &lt;td&gt;&lt;span class="genmed"&gt;&lt;b&gt;Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;	&lt;/tr&gt;	&lt;tr&gt;	  &lt;td id="code"&gt;&lt;br /&gt;Error in query: CREATE DATABASE testdatabase;. Can't create database 'testdatabase'; database exists&lt;br /&gt;&lt;/td&gt;	&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;That is because MySQL has a safety feature that prevents you from creating a database when one already exists.&lt;br /&gt;&lt;br /&gt;Also, note that we left the echo statement outside of any kind of checking loop that would make sure that the database WAS made. You might be thinking that it will still tell you that it made the database even if something goes wrong. However, if anything does go wrong in the script the "or die" command before the echo will KILL the script and the rest of the code below the "or die" will NOT run. Therefore, you will only see "Made Database $database" if the script works.&lt;br /&gt;&lt;br /&gt;Well, anyway - we just made a database! &lt;img src="http://www.learnphpfree.com/images/smiles/biggrin.gif" alt="Happy" border="0" /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;-----------------------------------------------------------&lt;br /&gt;-- Making a Table:&lt;br /&gt;-----------------------------------------------------------&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Now we need to make a table and some columns for the data we will put in our database.&lt;br /&gt;Open up makedb.php and change the code in it to this:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;  	  &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt; 	&lt;/tr&gt; 	&lt;tr&gt; 	  &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;7&lt;br/&gt;8&lt;br/&gt;9&lt;br/&gt;10&lt;br/&gt;11&lt;br/&gt;12&lt;br/&gt;13&lt;br/&gt;14&lt;br/&gt;15&lt;br/&gt;16&lt;br/&gt;17&lt;br/&gt;18&lt;br/&gt;19&lt;br/&gt;20&lt;br/&gt;21&lt;br/&gt;22&lt;br/&gt;23&lt;br/&gt;24&lt;br/&gt;25&lt;br/&gt;26&lt;br/&gt;27&lt;br/&gt;28&lt;br/&gt;29&lt;br/&gt;30&lt;br/&gt;31&lt;br/&gt;32&lt;br/&gt;33&lt;br/&gt;34&lt;br/&gt;35&lt;br/&gt;36&lt;br/&gt;37&lt;br/&gt;38&lt;br/&gt;&lt;/td&gt; --&gt; 	  &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Create the database access variables:&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$hostname &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"localhost"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$database &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"testdatabase"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$username &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"root"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$password &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;""&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Open a connection to the server&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$connection &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;mysql_connect&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$hostname&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$username&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$password&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) or die (&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Unable to connect to the DB Server!"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//////////&lt;br /&gt;//NEW CODE&lt;br /&gt;//////////&lt;br /&gt;&lt;br /&gt;// Select the database&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;mysql_select_db&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$database&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) or die (&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Can't select database!"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Make Table Query&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$query &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"CREATE TABLE `contacts` &lt;br /&gt;(&lt;br /&gt;`name` TEXT NOT NULL ,&lt;br /&gt;`phone` TEXT NOT NULL ,&lt;br /&gt;`address` TEXT NOT NULL&lt;br /&gt;)"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// execute query&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$result &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;mysql_query&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$query&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) or die (&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Error in query: &lt;br /&gt;$query. "&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;.&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;mysql_error&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;());&lt;br /&gt;&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Made table 'contacts'"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//////////&lt;br /&gt;//NEW CODE&lt;br /&gt;//////////&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt; 	&lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;Save it as "maketable.php" and upload it to your web server. If everything goes OK then you now have one table named "contacts" in your database.&lt;br /&gt;&lt;br /&gt;If you try to run this script a second time you will see the error:&lt;br /&gt;&lt;/span&gt;&lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="90%"&gt;&lt;tbody&gt;&lt;tr&gt; 	  &lt;td&gt;&lt;span class="genmed"&gt;&lt;b&gt;Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;	&lt;/tr&gt;	&lt;tr&gt;	  &lt;td id="code"&gt;&lt;br /&gt;Error in query: CREATE TABLE `contacts` ( `name` TEXT NOT NULL , `phone` TEXT NOT NULL , `address` TEXT NOT NULL ). Table 'contacts' already exists&lt;br /&gt;&lt;/td&gt;	&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;Again, this is becuase MySQL has a safety feature that prevents you from creating something when it already exists.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;-----------------------------------------------------------&lt;br /&gt;-- Adding Data to Your Database:&lt;br /&gt;-----------------------------------------------------------&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Now we need to &lt;span style="font-style: italic;"&gt;add&lt;/span&gt; data to our database.&lt;br /&gt;Open up maketable.php and change the code in it to this:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;  	  &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt; 	&lt;/tr&gt; 	&lt;tr&gt; 	  &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;7&lt;br/&gt;8&lt;br/&gt;9&lt;br/&gt;10&lt;br/&gt;11&lt;br/&gt;12&lt;br/&gt;13&lt;br/&gt;14&lt;br/&gt;15&lt;br/&gt;16&lt;br/&gt;17&lt;br/&gt;18&lt;br/&gt;19&lt;br/&gt;20&lt;br/&gt;21&lt;br/&gt;22&lt;br/&gt;23&lt;br/&gt;24&lt;br/&gt;25&lt;br/&gt;26&lt;br/&gt;27&lt;br/&gt;28&lt;br/&gt;29&lt;br/&gt;30&lt;br/&gt;31&lt;br/&gt;32&lt;br/&gt;33&lt;br/&gt;34&lt;br/&gt;35&lt;br/&gt;&lt;/td&gt; --&gt; 	  &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Create the database access variables:&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$hostname &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"localhost"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$database &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"testdatabase"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$username &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"root"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$password &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;""&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Open a connection to the server&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$connection &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;mysql_connect&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$hostname&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$username&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$password&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) or die (&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Unable to connect to the DB Server!"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Select the database&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;mysql_select_db&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$database&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) or die (&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Can't select database!"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//////////&lt;br /&gt;//NEW CODE&lt;br /&gt;//////////&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;// Make data query&lt;br /&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$query &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'INSERT INTO `contacts` (`name`, `phone`, `address`) VALUES (\'Bob\', \'999-555-5555\', \'TX\');'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// execute query&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$result &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;mysql_query&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$query&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) or die (&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Error in query: $query. &lt;br /&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;.&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;mysql_error&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;());&lt;br /&gt;&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"inserted Bob and his info into 'contacts'"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//////////&lt;br /&gt;//NEW CODE&lt;br /&gt;//////////&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt; 	&lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Save it as "makebob.php" and upload it to your web server. If everything goes OK then you will now have all of Bob's info in your database. &lt;img src="http://www.learnphpfree.com/images/smiles/tongue.gif" alt=":P" border="0" /&gt;&lt;br /&gt;&lt;br /&gt;Note: If you try to run this script a second time you will NOT see an error. This is because you are now &lt;span style="font-style: italic;"&gt;adding&lt;/span&gt; information to the database - and there is no limit on how much data you can add! If you run the script several times you will find that you will just have several rows all with Bob's data.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;-----------------------------------------------------------&lt;br /&gt;-- Showing your data:&lt;br /&gt;-----------------------------------------------------------&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Open back up makebob.php and change the code to this:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;  	  &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt; 	&lt;/tr&gt; 	&lt;tr&gt; 	  &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;7&lt;br/&gt;8&lt;br/&gt;9&lt;br/&gt;10&lt;br/&gt;11&lt;br/&gt;12&lt;br/&gt;13&lt;br/&gt;14&lt;br/&gt;15&lt;br/&gt;16&lt;br/&gt;17&lt;br/&gt;18&lt;br/&gt;19&lt;br/&gt;20&lt;br/&gt;21&lt;br/&gt;22&lt;br/&gt;23&lt;br/&gt;24&lt;br/&gt;25&lt;br/&gt;26&lt;br/&gt;27&lt;br/&gt;28&lt;br/&gt;29&lt;br/&gt;30&lt;br/&gt;31&lt;br/&gt;32&lt;br/&gt;33&lt;br/&gt;34&lt;br/&gt;35&lt;br/&gt;36&lt;br/&gt;37&lt;br/&gt;38&lt;br/&gt;39&lt;br/&gt;40&lt;br/&gt;41&lt;br/&gt;42&lt;br/&gt;43&lt;br/&gt;44&lt;br/&gt;45&lt;br/&gt;46&lt;br/&gt;47&lt;br/&gt;48&lt;br/&gt;49&lt;br/&gt;50&lt;br/&gt;51&lt;br/&gt;&lt;/td&gt; --&gt; 	  &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Create the database access variables:&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$hostname &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"localhost"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$database &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"testdatabase"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$username &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"root"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$password &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;""&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Open a connection to the server&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$connection &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;mysql_connect&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$hostname&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$username&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$password&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) or die (&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Unable to connect to the DB Server!"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Select the database&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;mysql_select_db&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$database&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) or die (&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Can't select database!"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//////////&lt;br /&gt;//NEW CODE&lt;br /&gt;//////////&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;// Show data query&lt;br /&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$query &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'SELECT * FROM `contacts`'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// execute query&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$result &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;mysql_query&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$query&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) or die (&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Error in query: $query. &lt;br /&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;.&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;mysql_error&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;());&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'&lt;table border="1"&gt;'&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;. &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'&lt;tr&gt;'&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;. &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'&lt;td&gt;Name&lt;/td&gt;'&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;. &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'&lt;td&gt;Phone&lt;/td&gt;'&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;. &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'&lt;td&gt;Address&lt;/td&gt;'&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;. &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'&lt;/tr&gt;'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    &lt;br /&gt;while(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$row &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;mysql_fetch_row&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$result&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)) {&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;tr&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;td&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;. &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$row&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]. &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;/td&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;td&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;. &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$row&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]. &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;/td&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;td&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;. &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$row&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;2&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]. &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;/td&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;/tr&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;}&lt;br /&gt;    &lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'&lt;/table&gt;'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//////////&lt;br /&gt;//NEW CODE&lt;br /&gt;//////////&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt; 	&lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;Save the new file as "showdata.php" and upload it to your web server. When you run it you should see a table with Name, Phone, and Address at the top and below it is each row from the database.&lt;br /&gt;&lt;br /&gt;The only code I need to explain is the &lt;span style="font-style: italic;"&gt;while&lt;/span&gt; loop:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;  	  &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt; 	&lt;/tr&gt; 	&lt;tr&gt; 	  &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;7&lt;br/&gt;&lt;/td&gt; --&gt; 	  &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;while(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$row &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;mysql_fetch_row&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$result&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)) {&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;tr&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;td&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;. &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$row&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]. &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;/td&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;td&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;. &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$row&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]. &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;/td&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;td&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;. &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$row&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;2&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]. &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;/td&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;/tr&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;} &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt; 	&lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;This code would read like this in English:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;  	  &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt; 	&lt;/tr&gt; 	&lt;tr&gt; 	  &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;7&lt;br/&gt;&lt;/td&gt; --&gt; 	  &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;while(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;the variable &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"$row" &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;is equal to a_row_fetched_from_the&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$result&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)) {&lt;br /&gt;    print &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;a &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;new &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;row in HTML &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;tr&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    print &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;a &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;new &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;column in HTML &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;td&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;. &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;then &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;print &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;out the value of the first element in $row &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$row&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]). &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;/td&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    print &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;a &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;new &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;column in HTML &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;td&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;. &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;then &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;print &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;out the value of the second element in $row &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$row&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]). &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;/td&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    print &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;a &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;new &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;column in HTML &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;td&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;. &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;then &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;print &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;out the value of the third element in $row &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$row&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;2&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]). &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;/td&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    print &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;a &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;new &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;end&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;-&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;row in HTML &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;/tr&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;} &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt; 	&lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;After, the loop runs one time it will go back to the start and it will see if there is &lt;span style="font-style: italic;"&gt;another&lt;/span&gt; row in the result ($row = mysql_fetch_row($result)) if there is; then code will run again and if NOT it will stop.&lt;br /&gt;&lt;br /&gt;I also would like to say that you could replace:&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;  	  &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt; 	&lt;/tr&gt; 	&lt;tr&gt; 	  &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;&lt;/td&gt; --&gt; 	  &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Show data query&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$query &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'SELECT * FROM `contacts`'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt; 	&lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;with:&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;  	  &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt; 	&lt;/tr&gt; 	&lt;tr&gt; 	  &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;&lt;/td&gt; --&gt; 	  &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Show data query&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$query &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'SELECT `name`, `phone`, `address` FROM `contacts`'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt; 	&lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;The script would still give the same result! This is because the first code says "SELECT ALL" and the second code says "SELECT `name`, `phone`, `address`" but since that is &lt;span style="font-weight: bold;"&gt;all of the columns&lt;/span&gt; in the table it is the same as saying "SELECT ALL"! &lt;br /&gt;&lt;img src="http://www.learnphpfree.com/images/smiles/tongue.gif" alt=":P" border="0" /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;That's it! &lt;img src="http://www.learnphpfree.com/images/smiles/biggrin.gif" alt="Happy" border="0" /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;-----------------------------------------------------------&lt;br /&gt;-- Other MySQL Queries:&lt;br /&gt;-----------------------------------------------------------&lt;/span&gt;&lt;br /&gt;Here are some other queries you can do with MySQL.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;DELETING:&lt;/span&gt;&lt;br /&gt;DELETE FROM `contacts` WHERE name=bob;&lt;br /&gt;&lt;br /&gt;DELETE * FROM `contacts`;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Update:&lt;/span&gt;&lt;br /&gt;UPDATE `contacts` SET name='newbob' WHERE name='Bob';&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Creating a Database:&lt;/span&gt;&lt;br /&gt;CREATE DATABASE `newdatabase`;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Showing what Databases are Available:&lt;/span&gt;&lt;br /&gt;SHOW DATABASES;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Showing what Tables are available in a database:&lt;/span&gt;&lt;br /&gt;SHOW TABLES;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Select Everything from a table in a Database:&lt;/span&gt;&lt;br /&gt;SELECT * FROM `yourtablename`;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Deleting a Database:&lt;/span&gt;&lt;br /&gt;DROP DATABASE `databasename`;&lt;br /&gt;&lt;br /&gt;-------------------------------------------------------------&lt;br /&gt;&lt;br /&gt; &lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4889431653894848295-7355627829765160572?l=domyat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://domyat.blogspot.com/feeds/7355627829765160572/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4889431653894848295&amp;postID=7355627829765160572' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4889431653894848295/posts/default/7355627829765160572'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4889431653894848295/posts/default/7355627829765160572'/><link rel='alternate' type='text/html' href='http://domyat.blogspot.com/2008/03/lesson-22-starting-off-with-databases.html' title='Lesson 22 - Starting off with Databases'/><author><name>elawael</name><uri>http://www.blogger.com/profile/11684828293686686914</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4889431653894848295.post-6088073975375453598</id><published>2008-03-31T08:35:00.000-07:00</published><updated>2008-03-31T08:36:09.168-07:00</updated><title type='text'>Lesson 21 - Making your own Functions</title><content type='html'>&lt;span class="postbody"&gt;I want to teach you how to make your &lt;span style="font-style: italic;"&gt;own&lt;/span&gt; functions now. We have been using lots of PHP's built-in functions, but did you know that you could make your own? &lt;br /&gt;&lt;br /&gt;A function is basically a command that tells the computer to carry out a certain set of instructions for you. For example:&lt;br /&gt;&lt;br /&gt;trim() - Strips white spaces from the begging and end of a string.&lt;br /&gt;mysql_query() - sends a MySQL queary.&lt;br /&gt;count() -- Counts the elements in an array, or properties in an object&lt;br /&gt;crypt() -- One-way string encryption (hashing)&lt;br /&gt;file() -- Reads an entire file into an array&lt;br /&gt;&lt;br /&gt;These are all &lt;span style="font-style: italic;"&gt;functions&lt;/span&gt; that people wrote to do these tasks for you rather than you having to build a bunch of loops or classes every time you want to do these things. With these functions all you do is:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$newstring &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;trim&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$string&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;As a pose to trying to write all of the code that would &lt;span style="font-style: italic;"&gt;trim&lt;/span&gt; the $string:&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;7&lt;br/&gt;8&lt;br/&gt;9&lt;br/&gt;10&lt;br/&gt;11&lt;br/&gt;12&lt;br/&gt;13&lt;br/&gt;14&lt;br/&gt;15&lt;br/&gt;16&lt;br/&gt;17&lt;br/&gt;18&lt;br/&gt;19&lt;br/&gt;20&lt;br/&gt;21&lt;br/&gt;22&lt;br/&gt;23&lt;br/&gt;24&lt;br/&gt;25&lt;br/&gt;26&lt;br/&gt;27&lt;br/&gt;28&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;foreach(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;count&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$string&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) as &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$var&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) {      &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;blah&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;... &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;blah&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;... &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;blah&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;.....&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;blah&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;... &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;blah&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;... &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;blah&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;.....&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;blah&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;... &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;blah&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;... &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;blah&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;.....&lt;br /&gt;    while (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$x &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$something&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) {&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;blah&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;... &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;blah&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;... &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;blah&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;.....&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;blah&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;... &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;blah&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;... &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;blah&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;.....&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;blah&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;... &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;blah&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;... &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;blah&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;.....&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;blah&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;... &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;blah&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;... &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;blah&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;.....&lt;br /&gt;    }&lt;br /&gt;    ....&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;more code&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;....&lt;br /&gt;    ....&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;blah&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;... &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;blah&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;... &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;blah&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;.....&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;blah&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;... &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;blah&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;... &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;blah&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;.....&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Well, if other people can make functions why can't you? Well...You can! So lets get to it!&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Here is the syntax for making a function:&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;7&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;function &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;fakefunction&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$argument_1&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$argument_2&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;/* ...more arguments..., */ &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$argument_n&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)&lt;br /&gt;{&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Example function.\n"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    return &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$returnvaliable&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;The first step is to type "function", this lets the computer know that you are going to make a function. Next you create a name for the function, we choose "fakefunction".&lt;br /&gt;&lt;br /&gt;NOTE: You want to be careful when you choose the name because there might already be a function by that name. If you want to find out if the name already exists visit the function index at php.net.&lt;br /&gt;&lt;br /&gt;After you choose a name you need to decide if there are going to be any &lt;span style="font-style: italic;"&gt;arguments&lt;/span&gt; passes to the function. An argument would be like a variable:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;function &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;does_user_exits&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$username&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) {&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;run code to see &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;if &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"username" &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;exists&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;If you didn't pass the function &lt;span style="font-style: italic;"&gt;does_user_exits()&lt;/span&gt; the variable "$username" how would you be able to see if that user existed? &lt;img src="http://www.learnphpfree.com/images/smiles/tongue.gif" alt=":P" border="0" /&gt;&lt;br /&gt;&lt;br /&gt;A real-life example is trim():&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$newstring &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;trim&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$string&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;If you didn't pass the function the name of the string too trim, what good would it do?&lt;br /&gt;&lt;br /&gt;Finally, you add all of the code that will make up the function and then when your done you let PHP know your finished by typing a closing " } ". So now lets get to it!&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;##########################################################&lt;br /&gt;##  PART 2: Making a function&lt;br /&gt;##########################################################&lt;br /&gt;&lt;br /&gt;Open up SciTE or Notpad and type this into it:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;7&lt;br/&gt;8&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;function &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;print_my_name&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;() {&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"My name is David"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;print_my_name&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;();&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;Note: I hope you changed David to &lt;span style="font-weight: bold;"&gt;your&lt;/span&gt; name... &lt;img src="http://www.learnphpfree.com/images/smiles/icon_wink.gif" alt="Wink" border="0" /&gt; &lt;br /&gt;&lt;br /&gt;Save the file as "printname.php" and upload it to your server. When you run "printname.php" you will see:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="90%"&gt;&lt;tbody&gt;&lt;tr&gt;    &lt;td&gt;&lt;span class="genmed"&gt;&lt;b&gt;Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt;   &lt;td id="code"&gt;&lt;br /&gt;My name is David&lt;br /&gt;&lt;/td&gt; &lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Now then, you have just made your first function! Give yourself a pat on the back.&lt;br /&gt;When the function print_my_name() is called it will run the code inside it. However, the only code is one line that prints out "My name is David".&lt;br /&gt;&lt;br /&gt;Also, realize that after you make the function you have to call it! Just because you wrote the function doesn't mean that it will run. You have to now tell PHP when and where you want that function to run. In this case we told the computer to run the function right away:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;print_my_name&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(); &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;However, we could have waited until later in the script or even &lt;span style="font-style: italic;"&gt;not&lt;/span&gt; run it at all! &lt;img src="http://www.learnphpfree.com/images/smiles/tongue.gif" alt=":P" border="0" /&gt;&lt;br /&gt;&lt;br /&gt;##########################################################&lt;br /&gt;##  PART 3: Making a &lt;span style="font-weight: bold;"&gt;USEFUL&lt;/span&gt; function&lt;br /&gt;##########################################################&lt;br /&gt;&lt;br /&gt;Open up SciTE or Notepad and type the following into it:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;7&lt;br/&gt;8&lt;br/&gt;9&lt;br/&gt;10&lt;br/&gt;11&lt;br/&gt;12&lt;br/&gt;13&lt;br/&gt;14&lt;br/&gt;15&lt;br/&gt;16&lt;br/&gt;17&lt;br/&gt;18&lt;br/&gt;19&lt;br/&gt;20&lt;br/&gt;21&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;function &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;print_out_file&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filename&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) {&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Read file into array called $contents&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$contents &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= @&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;file&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filename&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;    &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//if the array isn't empty (a.k.a. there was something in the file!)&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;if (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;count&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$contents&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) &gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) { &lt;br /&gt;    &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Loop through the array and print out the line (with a line-break (&lt;br /&gt;))&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;foreach (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$contents &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;as &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$row&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)&lt;br /&gt;        {&lt;br /&gt;           echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"$row &lt;br /&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;        }  &lt;br /&gt;    } else {&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// if $contents is equal to '0' or there was an error opening the file print:&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"File is empty or doesn't exist!"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;You can now save it as "file_functions.php" and upload it to your server. Next, start a new document and type this into it:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;include (&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"file_functions.php"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;print_out_file&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"testfile.txt"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;Then save it as "printfile.php" (or whatever you want to call it) and upload it to your web server. Open your browser and go to "printfile.php". When you do you should get a nice error message saying:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="90%"&gt;&lt;tbody&gt;&lt;tr&gt;    &lt;td&gt;&lt;span class="genmed"&gt;&lt;b&gt;Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt;   &lt;td id="code"&gt;&lt;br /&gt;File is empty or doesn't exist!&lt;br /&gt;&lt;/td&gt; &lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;Can you figure out why? (Hint: read the error &lt;img src="http://www.learnphpfree.com/images/smiles/tongue.gif" alt=":P" border="0" /&gt;) &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;That's right! There IS no file called "testfile.txt"! So start your editor one more time and type five lines of anything you want into it:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="90%"&gt;&lt;tbody&gt;&lt;tr&gt;    &lt;td&gt;&lt;span class="genmed"&gt;&lt;b&gt;Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt;   &lt;td id="code"&gt;&lt;br /&gt;This is line One.&lt;br /&gt;This is line Two.&lt;br /&gt;This is line Three.&lt;br /&gt;This is line Four.&lt;br /&gt;This is line Five.&lt;br /&gt;&lt;/td&gt; &lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;Save it as "testfile.txt" then upload it to your web server. Once all three are on the internet (and in the same directory) open your browser and go to "printfile.php".&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;This time you have passed a file that &lt;span style="font-style: italic;"&gt;actually exists&lt;/span&gt; to your function and it was able to open the file. So you should see this on the screen:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="90%"&gt;&lt;tbody&gt;&lt;tr&gt;    &lt;td&gt;&lt;span class="genmed"&gt;&lt;b&gt;Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt;   &lt;td id="code"&gt;&lt;br /&gt;This is line One.&lt;br /&gt;This is line Two.&lt;br /&gt;This is line Three.&lt;br /&gt;This is line Four.&lt;br /&gt;This is line Five.&lt;br /&gt;&lt;/td&gt; &lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Now then, you have just made your first &lt;span style="font-weight: bold;"&gt;useful&lt;/span&gt; function! Give yourself another pat on the back, lol.&lt;br /&gt;I trust you understand the code &lt;span style="font-style: italic;"&gt;inside&lt;/span&gt; the function. If not, you need to read the past lessons &lt;img src="http://www.learnphpfree.com/images/smiles/tongue.gif" alt=":P" border="0" /&gt;. So onto the description of what is going on here:&lt;br /&gt;&lt;br /&gt;First we made the file "file_functions.php" and we created a function called "print_out_file()". That function is only passed one argument - the name of the file to print out.&lt;br /&gt;&lt;br /&gt;Then we made "printfile.php" which was a simple two line script that included "file_functions.php" and then ran the function. Because the function is in it's own file we can now use &lt;span style="font-style: italic;"&gt;print_out_file()&lt;/span&gt; in any script we want simply by including the file "file_functions" and then typing &lt;span style="font-style: italic;"&gt;print_out_file()&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;SIDE NOTE:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::&lt;br /&gt;&lt;br /&gt;By making the function and putting it into its own file we can keep our code clean. Imagine if we had a large function in the middle of a good-sized script. If we were trying to find an error it would be a pain to search the whole document.&lt;br /&gt;&lt;br /&gt;Note: Just for those who would like to see it - here is what the file would look like if we stuck the function into "printfile.php":&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;7&lt;br/&gt;8&lt;br/&gt;9&lt;br/&gt;10&lt;br/&gt;11&lt;br/&gt;12&lt;br/&gt;13&lt;br/&gt;14&lt;br/&gt;15&lt;br/&gt;16&lt;br/&gt;17&lt;br/&gt;18&lt;br/&gt;19&lt;br/&gt;20&lt;br/&gt;21&lt;br/&gt;22&lt;br/&gt;23&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;function &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;print_out_file&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filename&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) {&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Read file into array called $contents&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$contents &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= @&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;file&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filename&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;    &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//if the array isn't empty (a.k.a. there was something in the file!)&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;if (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;count&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$contents&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) &gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) { &lt;br /&gt;    &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Loop through the array and print out the line (with a line-break (&lt;br /&gt;))&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;foreach (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$contents &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;as &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$row&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)&lt;br /&gt;        {&lt;br /&gt;           echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"$row &lt;br /&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;        }  &lt;br /&gt;    } else {&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// if $contents is equal to '0' or there was an error opening the file print:&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"File is empty or doesn't exist!"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;print_out_file&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"testfile.txt"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;While this would work just fine; like I said, by sticking the function in it's &lt;span style="font-style: italic;"&gt;own file&lt;/span&gt; it keeps the code clean for &lt;span style="font-style: italic;"&gt;larger&lt;/span&gt; scripts.&lt;br /&gt;&lt;br /&gt;Plus, by having the function in it's own file any script on our server can use the function by just including the file!&lt;br /&gt;&lt;br /&gt;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Ok, that's it! Try making your own functions for things you do often! For example I put the entire HTML Header and Footer for my pages into two functions called page_header() and page_footer() then have all of my pages just include the function.php page and then I run page_header() and page_footer():&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;7&lt;br/&gt;8&lt;br/&gt;9&lt;br/&gt;10&lt;br/&gt;11&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;include(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"functions.php"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;page_header&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;();&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Main content here&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;page_footer&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;();&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt; &lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4889431653894848295-6088073975375453598?l=domyat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://domyat.blogspot.com/feeds/6088073975375453598/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4889431653894848295&amp;postID=6088073975375453598' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4889431653894848295/posts/default/6088073975375453598'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4889431653894848295/posts/default/6088073975375453598'/><link rel='alternate' type='text/html' href='http://domyat.blogspot.com/2008/03/lesson-21-making-your-own-functions.html' title='Lesson 21 - Making your own Functions'/><author><name>elawael</name><uri>http://www.blogger.com/profile/11684828293686686914</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4889431653894848295.post-7899943280972978643</id><published>2008-03-31T08:34:00.000-07:00</published><updated>2008-03-31T08:35:19.028-07:00</updated><title type='text'>Lesson 20 - Including files with PHP's Include function</title><content type='html'>&lt;span class="postbody"&gt;Now that we know how to wield the POWER of PHP's file API lets kill some orc's! &lt;img src="http://www.learnphpfree.com/images/smiles/icon_twisted.gif" alt="Twisted Evil" border="0" /&gt; &lt;br /&gt;uh.. wait...that's not, *quite* right...&lt;br /&gt;&lt;br /&gt;*ahem&lt;br /&gt;&lt;br /&gt;Actually, what I was going to say is:&lt;br /&gt;Now that we know how to read and write to files let me show you how to &lt;span style="font-style: italic;"&gt;include&lt;/span&gt; other PHP files in your scripts. &lt;br /&gt;&lt;br /&gt;If you have ever coded in another language I am sure your saying "it's about time!". After all, including other files will become the basis for many of your scripts. If you think about it, it makes more sense to have a several different files that you can include if you want - as appose to having ONE huge file.&lt;br /&gt;&lt;br /&gt;There are two main functions for including files into your script:&lt;br /&gt;include();&lt;br /&gt;require();&lt;br /&gt;Basically, the only difference is that if &lt;span style="font-style: italic;"&gt;include&lt;/span&gt; can't get the file you will get an error, but the script will still run. However, if &lt;span style="font-style: italic;"&gt;require&lt;/span&gt; can't get the file your script will terminate with an error. Therefore, it is better to use &lt;span style="font-style: italic;"&gt;include&lt;/span&gt; if you still want your script to keep going &lt;span style="font-style: italic;"&gt;even&lt;/span&gt; if the file can't be opened.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;So to get you used to &lt;span style="font-style: italic;"&gt;including&lt;/span&gt; files I want you to open your text editor and type the following into it:&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;7&lt;br/&gt;8&lt;br/&gt;9&lt;br/&gt;10&lt;br/&gt;11&lt;br/&gt;12&lt;br/&gt;13&lt;br/&gt;14&lt;br/&gt;15&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;br /&gt;$number &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;if (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$number &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;== &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) {&lt;br /&gt;    include(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"somedumbfile.php"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;if (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$number &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;== &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) {&lt;br /&gt;    include(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"saying.php"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"The included file says:&lt;br /&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$saying&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;Save the file as "includetest.php" and then up load it to your web server. If you run it you will get an error saying that there is no variable called "$saying", so... open back up your editor and make a &lt;span style="font-style: italic;"&gt;new&lt;/span&gt; file called "saying.php". Enter this into it: &lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;br /&gt;$saying &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"There are ten kinds of people in the world - those that understand binary, and those that don't."&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//Note: if you don't get the joke just enter something else...sheesh!&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;Then upload this file to your web server and run "includetest.php" again. This time you will see "includetest.php" print out what you entered in "saying.php"! That is because the variable &lt;span style="font-style: italic;"&gt;$saying&lt;/span&gt; was &lt;span style="font-style: italic;"&gt;passed&lt;/span&gt; from the included file to "includetest.php":&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="90%"&gt;&lt;tbody&gt;&lt;tr&gt;    &lt;td&gt;&lt;span class="genmed"&gt;&lt;b&gt;Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt;   &lt;td id="code"&gt;&lt;br /&gt;The included file says:&lt;br /&gt;There are ten kinds of people in the world - those that understand binary, and those that don't.&lt;br /&gt;&lt;/td&gt; &lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;Now I am sure that you are starting to get ideas from this. I know that I was amazed when I first learned you could &lt;span style="font-style: italic;"&gt;include&lt;/span&gt; files in PHP. &lt;br /&gt;&lt;br /&gt;Honestly, I have a confession to make - I learned PHP just for the &lt;span style="font-style: italic;"&gt;include&lt;/span&gt; function! &lt;img src="http://www.learnphpfree.com/images/smiles/icon_wink.gif" alt="Wink" border="0" /&gt;&lt;br /&gt;&lt;br /&gt;Up until then, I had only been using HTML for my sites. It was a MAJOR pain to open each and every file and change the navigation bar &lt;span style="font-style: italic;"&gt;every&lt;/span&gt; time I added something. However, with PHP you can just make ONE navigation file that has the nav bar and then &lt;span style="font-style: italic;"&gt;include&lt;/span&gt; it into &lt;span style="font-style: italic;"&gt;every&lt;/span&gt; page that needs the nav bar. That way you only have to change "nav.php" and &lt;span style="font-style: italic;"&gt;every&lt;/span&gt; page on your site will have the new nav bar! Trust me, this is an AWESOME feature if you have a site with 100+ pages - as there is no way that you could open all of them up and change the nav bar! &lt;img src="http://www.learnphpfree.com/images/smiles/icon_eek.gif" alt="Shocked" border="0" /&gt;&lt;br /&gt;&lt;br /&gt;This site is a perfect example of using &lt;span style="font-style: italic;"&gt;include&lt;/span&gt; to build a web page.&lt;br /&gt;There is a header, content, and footer file on my server. In order to show this page PHP runs a script that looks like this:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;include(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"header.php"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;include(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"content.php"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;include(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"footer.php"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;Now this is very different than what this page &lt;span style="font-style: italic;"&gt;actually&lt;/span&gt; does, but the idea is the same. &lt;img src="http://www.learnphpfree.com/images/smiles/icon_wink.gif" alt="Wink" border="0" /&gt;&lt;br /&gt;&lt;br /&gt;Every time I open "header.php" and add a new thing to the banner area above all of the pages on my site then have the new code because they all &lt;span style="font-style: italic;"&gt;include&lt;/span&gt; "header.php" before they show you the page. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;So, now that you know about &lt;span style="font-style: italic;"&gt;include&lt;/span&gt; lets build a simple page that is made up of different files that all come together to make what you see! Open up SciTE or Notepad and enter this into it:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;7&lt;br/&gt;8&lt;br/&gt;9&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;table border="\"&gt;&lt;tr&gt;&lt;td&gt;Here is the Header:&lt;br /&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;include(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"header.php"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;This is the Content area:&lt;br /&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;include(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"content.php"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Here you could put the copyright:&lt;br /&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;include(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"footer.php"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;Then save it as "webpage.php".&lt;br /&gt;Now you need to create three more files; "header.php", "content.php", and "footer.php". Create each one and put anything you want into them. Then take all four files and upload them to your web server. If you need ideas look at this:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;7&lt;br/&gt;8&lt;br/&gt;9&lt;br/&gt;10&lt;br/&gt;11&lt;br/&gt;12&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Header.php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"this is the header"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;br /&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Content.php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"This is the stuff that the whole page is actually about!"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;br /&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Footer.php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&amp;amp;copy 2006 learnphpfree.com"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;After you have uploaded website.php, header.php, content.php, and footer.php; run website.php. You will see something like this:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="90%"&gt;&lt;tbody&gt;&lt;tr&gt;    &lt;td&gt;&lt;span class="genmed"&gt;&lt;b&gt;Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt;   &lt;td id="code"&gt;&lt;br /&gt;Here is the Header:&lt;br /&gt;this is the header&lt;br /&gt;This is the Content area:&lt;br /&gt;This is the stuff that the whole page is actually about!&lt;br /&gt;Here you could put the copyright:&lt;br /&gt;? 2006 learnphpfree.com&lt;br /&gt;&lt;/td&gt; &lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;span class="postbody"&gt;&lt;br /&gt;(with a border around each part!)&lt;br /&gt;&lt;br /&gt;Well, this is nothing special so let me show you something more useful. You could change the "website.php" code to this:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;7&lt;br/&gt;8&lt;br/&gt;9&lt;br/&gt;10&lt;br/&gt;11&lt;br/&gt;12&lt;br/&gt;13&lt;br/&gt;14&lt;br/&gt;15&lt;br/&gt;16&lt;br/&gt;17&lt;br/&gt;18&lt;br/&gt;19&lt;br/&gt;20&lt;br/&gt;21&lt;br/&gt;22&lt;br/&gt;23&lt;br/&gt;24&lt;br/&gt;25&lt;br/&gt;26&lt;br/&gt;27&lt;br/&gt;28&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;include (&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"header.php"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;///////////////////////////////////////////////////////////////&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$pagetoget &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'pagename'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;];&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//Get the page that the user wants to see and put it in a var.&lt;br /&gt;&lt;br /&gt;//Now we find the page that the user wanted to see and "include" it.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;if (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$pagetoget &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;== &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"help"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) {&lt;br /&gt;    include (&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"help.php"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;}&lt;br /&gt;elseif (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$pagetoget &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;== &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"about"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) {&lt;br /&gt;    include (&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"about.php"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;}&lt;br /&gt;elseif (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$pagetoget &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;== &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"help"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) {&lt;br /&gt;    include (&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"about.php"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;}&lt;br /&gt;else {&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// If no pages match just show the home page.&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;include (&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"home.php"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;///////////////////////////////////////////////////////////////&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;include (&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"footer.php"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;In this example, website.php is passed a page name and the script &lt;span style="font-style: italic;"&gt;includes&lt;/span&gt; the corresponding page. In this way you can actually just use ONE page to build and print all of the pages on your site! That way you don't have to worry about re-coding the WHOLE page for every page you have. Just make part of a page with the content on it and BOOM! let you main page grab the "header" and "footer" pages and put it all together.&lt;br /&gt;&lt;br /&gt;Like always, if you want to learn &lt;span style="font-style: italic;"&gt;more&lt;/span&gt; about include() or require() stop by &lt;a href="http://www.php.net/" target="_blank" class="postlink"&gt;php.net&lt;/a&gt; and then do a search on &lt;a href="http://www.google.com/search?hl=en&amp;amp;q=php+include&amp;amp;btnG=Google+Search" target="_blank" class="postlink"&gt;Google&lt;/a&gt;. Later! &lt;img src="http://www.learnphpfree.com/images/smiles/biggrin.gif" alt="Happy" border="0" /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4889431653894848295-7899943280972978643?l=domyat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://domyat.blogspot.com/feeds/7899943280972978643/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4889431653894848295&amp;postID=7899943280972978643' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4889431653894848295/posts/default/7899943280972978643'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4889431653894848295/posts/default/7899943280972978643'/><link rel='alternate' type='text/html' href='http://domyat.blogspot.com/2008/03/lesson-20-including-files-with-phps.html' title='Lesson 20 - Including files with PHP&apos;s Include function'/><author><name>elawael</name><uri>http://www.blogger.com/profile/11684828293686686914</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4889431653894848295.post-1365640665321734007</id><published>2008-03-31T08:33:00.002-07:00</published><updated>2008-03-31T08:35:06.921-07:00</updated><title type='text'>Lesson 19 - Reading External Files into PHP - Part 4</title><content type='html'>&lt;span class="postbody"&gt;Now that we know how to read and write to files, lets make something. Do you remember the simple "Chat System" from lesson 11? Lets turn it into a REAL chat system. (One that won't &lt;span style="font-style: italic;"&gt;forget&lt;/span&gt; the messages!) So open SciTE (or Notepad) and type the following into it: &lt;br /&gt;(Do NOT copy and paste the code! You need to learn it and typing it will help you to focus on it.)&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;  	  &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt; 	&lt;/tr&gt; 	&lt;tr&gt; 	  &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;7&lt;br/&gt;8&lt;br/&gt;9&lt;br/&gt;10&lt;br/&gt;11&lt;br/&gt;12&lt;br/&gt;13&lt;br/&gt;14&lt;br/&gt;15&lt;br/&gt;16&lt;br/&gt;17&lt;br/&gt;18&lt;br/&gt;19&lt;br/&gt;20&lt;br/&gt;21&lt;br/&gt;22&lt;br/&gt;23&lt;br/&gt;24&lt;br/&gt;25&lt;br/&gt;26&lt;br/&gt;27&lt;br/&gt;28&lt;br/&gt;29&lt;br/&gt;30&lt;br/&gt;31&lt;br/&gt;32&lt;br/&gt;33&lt;br/&gt;34&lt;br/&gt;35&lt;br/&gt;36&lt;br/&gt;37&lt;br/&gt;38&lt;br/&gt;39&lt;br/&gt;40&lt;br/&gt;41&lt;br/&gt;42&lt;br/&gt;43&lt;br/&gt;44&lt;br/&gt;45&lt;br/&gt;46&lt;br/&gt;47&lt;br/&gt;48&lt;br/&gt;49&lt;br/&gt;50&lt;br/&gt;51&lt;br/&gt;52&lt;br/&gt;53&lt;br/&gt;54&lt;br/&gt;55&lt;br/&gt;56&lt;br/&gt;57&lt;br/&gt;58&lt;br/&gt;59&lt;br/&gt;60&lt;br/&gt;61&lt;br/&gt;62&lt;br/&gt;63&lt;br/&gt;64&lt;br/&gt;65&lt;br/&gt;66&lt;br/&gt;67&lt;br/&gt;68&lt;br/&gt;69&lt;br/&gt;70&lt;br/&gt;71&lt;br/&gt;72&lt;br/&gt;73&lt;br/&gt;74&lt;br/&gt;75&lt;br/&gt;76&lt;br/&gt;77&lt;br/&gt;78&lt;br/&gt;79&lt;br/&gt;80&lt;br/&gt;81&lt;br/&gt;82&lt;br/&gt;83&lt;br/&gt;&lt;/td&gt; --&gt; 	  &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;/////////////////////////////////////////////////////////////////////////&lt;br /&gt;// Put the page layout in some strings:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filename &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"chatfile.txt"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$startofpage &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;html&gt;&lt;body&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;table border="\"&gt;&lt;tr&gt;&lt;td&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$endofpage &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/center&gt;&lt;/body&gt;&lt;html&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$form &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;form action="\" method="\"&gt;&lt;br /&gt;        &lt;textarea name="\" rows="\" cols="\"&gt;&lt;/textarea&gt;&lt;br /&gt;        &lt;br /&gt;&lt;input name="\" type="\" value="\"&gt;&lt;br /&gt;        &lt;/form&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;/* &lt;br /&gt;Now that we have a basic layout in a few strings&lt;br /&gt;we can move onto writing the code. &lt;br /&gt;*/&lt;br /&gt;/////////////////////////////////////////////////////////////////////////&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;if (isset(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'text'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;])) {&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;///////////////////////////////////////&lt;br /&gt;    // Clean the text from HTML, PHP, and Cussing&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$text &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;strip_tags&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;trim&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'text'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]));&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$badwords &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= array(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"sucks"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"damn"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"#!@?"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"ASP"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$text &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;str_replace&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$badwords&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"****"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"$text"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$text &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;.= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;":END:\n"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;///////////////////////////////////////&lt;br /&gt;    &lt;br /&gt;    &lt;br /&gt;    &lt;br /&gt;    &lt;br /&gt;    &lt;br /&gt;    ////////////////////////////////////////////////////////////&lt;br /&gt;    // We create the filehandle and set the mode to write ("a")&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filehandle &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;fopen&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filename&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'a'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) or die(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'Could not open the file'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;    if (!&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;fwrite&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filehandle&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$text&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)) {&lt;br /&gt;        echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Could not add the post to the file!"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    } else {&lt;br /&gt;        echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;br /&gt;&lt;span style="color:\;"&gt;Added your comment!&lt;/span&gt;&lt;br /&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;fclose&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filehandle&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;////////////////////////////////////////////////////////////&lt;br /&gt;    &lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;}&lt;br /&gt;    &lt;br /&gt;    &lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;/////////////////////////////////////////////////////////////////////////&lt;br /&gt;// Now we need to open the file back up and pull out all of the comments.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$contents &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;file&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filename&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;br /&gt;if (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;count&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$contents&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) &gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) { &lt;br /&gt;&lt;br /&gt;    foreach (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$contents &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;as &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$row&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)&lt;br /&gt;    {&lt;br /&gt;       &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$comment &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;str_replace&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;":END:"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;hr /&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$row&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;       &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$comment &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;str_replace&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"\n"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;br /&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$comment&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;       &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$usercomments &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;.= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$comment&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    }  &lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;/////////////////////////////////////////////////////////////////////////&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/////////////////////////////////////////////////////////////////////////&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;if (!isset(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$usercomments&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)) {&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$usercomments &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"There are no comments"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$usercomments &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;br /&gt;&lt;br /&gt;&lt;div align="\" border="\"&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;. &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$usercomments&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;. &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;div&gt;&lt;br /&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    &lt;br /&gt;    &lt;br /&gt;    &lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$startofpage&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$usercomments&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$form&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$endofpage&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt; 	&lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;When you are done typing in that code, save it as "chatscript.php" and upload (FTP) it to your web server. Before you go on, try to just read through the code and see if you can follow the logic. Then run it a couple of times and post different things and see if you can understand most of the code.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Now here is the break-down of the script: &lt;br /&gt;&lt;br /&gt;1) We start by putting the layout, filename, and comment form into strings so that we can keep our code clean by just using a string instead of putting all of that code into our loops...&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;  	  &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt; 	&lt;/tr&gt; 	&lt;tr&gt; 	  &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;7&lt;br/&gt;8&lt;br/&gt;9&lt;br/&gt;10&lt;br/&gt;11&lt;br/&gt;12&lt;br/&gt;13&lt;br/&gt;14&lt;br/&gt;15&lt;br/&gt;16&lt;br/&gt;17&lt;br/&gt;18&lt;br/&gt;19&lt;br/&gt;&lt;/td&gt; --&gt; 	  &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;/////////////////////////////////////////////////////////////////////////&lt;br /&gt;// Put the page layout in some strings:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filename &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"chatfile.txt"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$startofpage &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;html&gt;&lt;body&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;table border="\"&gt;&lt;tr&gt;&lt;td&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$endofpage &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/center&gt;&lt;/body&gt;&lt;html&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$form &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;form action="\" method="\"&gt;&lt;br /&gt;        &lt;textarea name="\" rows="\" cols="\"&gt;&lt;/textarea&gt;&lt;br /&gt;        &lt;br /&gt;&lt;input name="\" type="\" value="\"&gt;&lt;br /&gt;        &lt;/form&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;/* &lt;br /&gt;Now that we have a basic layout in a few strings&lt;br /&gt;we can move onto writing the code. &lt;br /&gt;*/&lt;br /&gt;/////////////////////////////////////////////////////////////////////////&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt; 	&lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;2) Next we check to see if anything was POSTED to the page. This will evaluate to FALSE if nothing has been "Posted" to the page (and FALSE means that it won't run).&lt;br /&gt;However, after something has BEEN posted then this will be TRUE and the loop will run:&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;  	  &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt; 	&lt;/tr&gt; 	&lt;tr&gt; 	  &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;7&lt;br/&gt;8&lt;br/&gt;9&lt;br/&gt;10&lt;br/&gt;11&lt;br/&gt;12&lt;br/&gt;13&lt;br/&gt;14&lt;br/&gt;15&lt;br/&gt;16&lt;br/&gt;17&lt;br/&gt;18&lt;br/&gt;19&lt;br/&gt;20&lt;br/&gt;21&lt;br/&gt;22&lt;br/&gt;23&lt;br/&gt;&lt;/td&gt; --&gt; 	  &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;if (isset(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'text'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;])) {&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;///////////////////////////////////////&lt;br /&gt;    &lt;br /&gt;    // Clean the text from HTML and PHP So that no one messes up the page!&lt;br /&gt;    // trim() deletes the white spaces at the end of a string.&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$text &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;strip_tags&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;trim&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'text'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]));&lt;br /&gt;    &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Make an array called $badwords that has bad words as each array element&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$badwords &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= array(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"sucks"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"damn"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"#!@?"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"ASP"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Then we replace all of the matching bad words in $text with "****"&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$text &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;str_replace&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$badwords&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"****"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"$text"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;    &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// We need to add something that we can split the text with:&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$text &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;.= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;":END:\n"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;/*&lt;br /&gt;    The ( . ) char before the "=" means "add to $text", and the "\n" is the text version of pressing "Enter" on the keyboard. We added the "\n" so that each comment will be on a different line in the file.&lt;br /&gt;    */&lt;br /&gt;    ///////////////////////////////////////&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt; 	&lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;After we determined that a message was posted we then clean the message of all of the PHP, HTML, and Cussing that could ruin our conversation or point to spam sites. Finally we add ":END:\n" to the end of the text so that we can tell each comment apart.&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;3) Now that we have the cleaned message ready, we open the file and write the new text to it:&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;  	  &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt; 	&lt;/tr&gt; 	&lt;tr&gt; 	  &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;7&lt;br/&gt;8&lt;br/&gt;9&lt;br/&gt;10&lt;br/&gt;11&lt;br/&gt;12&lt;br/&gt;13&lt;br/&gt;14&lt;br/&gt;15&lt;br/&gt;16&lt;br/&gt;17&lt;br/&gt;18&lt;br/&gt;19&lt;br/&gt;20&lt;br/&gt;&lt;/td&gt; --&gt; 	  &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;    &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;////////////////////////////////////////////////////////////&lt;br /&gt;    // We create the file handle and set the mode to write ("a")&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filehandle &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;fopen&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filename&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'a'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) or die(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'Could not open the file'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;    &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Now we take the new comment and put it into the text file.&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;if (!&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;fwrite&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filehandle&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$text&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)) {&lt;br /&gt;        echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Could not add the post to the file!"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    } else {&lt;br /&gt;        echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;br /&gt;&lt;span style="color:\;"&gt;Added your comment!&lt;/span&gt;&lt;br /&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;fclose&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filehandle&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//Then close the file&lt;br /&gt;    ////////////////////////////////////////////////////////////&lt;br /&gt;    &lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;}&lt;br /&gt;    &lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt; 	&lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;For those of you who don't know loops (read the lessons on them) I am going to write the [if][/i] loop in English:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;  	  &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt; 	&lt;/tr&gt; 	&lt;tr&gt; 	  &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;7&lt;br/&gt;8&lt;br/&gt;9&lt;br/&gt;10&lt;br/&gt;11&lt;br/&gt;12&lt;br/&gt;13&lt;br/&gt;14&lt;br/&gt;15&lt;br/&gt;&lt;/td&gt; --&gt; 	  &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;if (!&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;fwrite&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filehandle&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$text&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)) {&lt;br /&gt;        echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Could not add the post to the file!"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    } else {&lt;br /&gt;        echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;br /&gt;&lt;span style="color:\;"&gt;Added your comment!&lt;/span&gt;&lt;br /&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Would look like this to a human:&lt;br /&gt;    &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;if &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;You&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;CANNOT write the $text to the file&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) {&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;tell the user&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;: &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Could not add the post to the file!"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    } &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;otherwise &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;if &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;you COULD write to the file &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;{&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;tell the user&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;: &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;br /&gt;&lt;span style="color:\;"&gt;Added your comment!&lt;/span&gt;&lt;br /&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    }&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt; 	&lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;4) Now that we just finished checking to see if a message was posted it is time to show all of the messages in the file:&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;  	  &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt; 	&lt;/tr&gt; 	&lt;tr&gt; 	  &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;7&lt;br/&gt;8&lt;br/&gt;9&lt;br/&gt;10&lt;br/&gt;11&lt;br/&gt;12&lt;br/&gt;13&lt;br/&gt;14&lt;br/&gt;15&lt;br/&gt;16&lt;br/&gt;17&lt;br/&gt;18&lt;br/&gt;19&lt;br/&gt;20&lt;br/&gt;21&lt;br/&gt;22&lt;br/&gt;23&lt;br/&gt;24&lt;br/&gt;25&lt;br/&gt;26&lt;br/&gt;27&lt;br/&gt;28&lt;br/&gt;29&lt;br/&gt;30&lt;br/&gt;31&lt;br/&gt;32&lt;br/&gt;33&lt;br/&gt;34&lt;br/&gt;35&lt;br/&gt;36&lt;br/&gt;37&lt;br/&gt;&lt;/td&gt; --&gt; 	  &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;br /&gt;    &lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;/////////////////////////////////////////////////////////////////////////&lt;br /&gt;// Now we need to open the file back up and pull out all of the comments.&lt;br /&gt;&lt;br /&gt;// Read file into array called $contents&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$contents &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;file&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filename&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//if the array isn't empty (a.k.a. there was something in the file!)&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;if (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;count&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$contents&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) &gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) { &lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Loop through the array and after fixing each row &lt;br /&gt;    // add the fixed array element to the $usercomments string&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;foreach (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$contents &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;as &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$row&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)&lt;br /&gt;    {&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;/* &lt;br /&gt;        First we need to separate the comments by Replacing&lt;br /&gt;        any :END:'s with a &lt;hr /&gt;. &lt;br /&gt;        */&lt;br /&gt;       &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$comment &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;str_replace&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;":END:"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;hr /&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$row&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;       &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;/*&lt;br /&gt;        Then we replace any "newline"&lt;br /&gt;        chars (\n) with a &lt;br /&gt; so that if someone presses Return&lt;br /&gt;        in the textarea the new line will show up right when we show &lt;br /&gt;        the comment.&lt;br /&gt;        */&lt;br /&gt;       &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$comment &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;str_replace&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"\n"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;br /&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$comment&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;       &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// ADD the finished array element to the $usercomments &lt;br /&gt;       // string and start the loop over:&lt;br /&gt;       &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$usercomments &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;.= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$comment&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    }  &lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;/////////////////////////////////////////////////////////////////////////&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt; 	&lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;In English the &lt;span style="font-style: italic;"&gt;if&lt;/span&gt; loop would read:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;  	  &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt; 	&lt;/tr&gt; 	&lt;tr&gt; 	  &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;7&lt;br/&gt;8&lt;br/&gt;&lt;/td&gt; --&gt; 	  &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;if &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;the&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;number of &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;array &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;elements in &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"$contents" &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;is greater than &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;or &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;equal to 1&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) { do &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;this&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;:&lt;br /&gt;    foreach (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;of the elements in &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"$contents"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;put that element in a &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;var &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;called &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"$row"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)&lt;br /&gt;    {&lt;br /&gt;    ...[do &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;the code HERE&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]....&lt;br /&gt;    } &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;Now that we are done with that &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;array &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;element &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;empty &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"$row" &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;and &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;go to the next element&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;.&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt; 	&lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;5) After we have grabbed all of the comments out of the file we just need to make another "safety" loop that will print "There are no comments" if for some reason the file is empty:&lt;br /&gt;(Note: This is just a nice thing to add)&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;  	  &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt; 	&lt;/tr&gt; 	&lt;tr&gt; 	  &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;7&lt;br/&gt;8&lt;br/&gt;9&lt;br/&gt;10&lt;br/&gt;11&lt;br/&gt;12&lt;br/&gt;&lt;/td&gt; --&gt; 	  &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;/* &lt;br /&gt;If $usercomments has not been set then there are no comments! Because the loop&lt;br /&gt;was never run (it equaled FALSE) and so the variable "$usercomments" was never made!&lt;br /&gt;so lets make the $usercomments string and put a warning sentence in it.&lt;br /&gt;*/&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;if (!isset(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$usercomments&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)) {&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$usercomments &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"There are no comments"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;}&lt;br /&gt;    &lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt; 	&lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;6) Finally, We add some formatting to the comments so that they stay in a box. and print everything to the screen!&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;  	  &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt; 	&lt;/tr&gt; 	&lt;tr&gt; 	  &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;7&lt;br/&gt;8&lt;br/&gt;9&lt;br/&gt;10&lt;br/&gt;11&lt;br/&gt;12&lt;br/&gt;13&lt;br/&gt;14&lt;br/&gt;&lt;/td&gt; --&gt; 	  &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;    &lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Lets add some formatting to the comments:&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$usercomments &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;br /&gt;&lt;br /&gt;&lt;div align="\" border="\"&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;. &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$usercomments&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;. &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;div&gt;&lt;br /&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    &lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;/////////////////////////////////////////////////////////////////////////&lt;br /&gt;// Now just show the finished result:&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$startofpage&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$usercomments&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$form&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$endofpage&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;/////////////////////////////////////////////////////////////////////////&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt; 	&lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Wow, good job! You finished it! (It took me &lt;span style="font-style: italic;"&gt;ALL DAY&lt;/span&gt; to write this lesson!) Doesn't it feel good to have made something cool?!&lt;br /&gt;&lt;br /&gt;Now I hope you followed the code and can now understand all of the loops and functions in it (If you are having trouble review the past lessons). If you just take code in small pieces it is a LOT easier to understand, so don't let anything intimidate you!&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;(Note: You can download the script at the bottom.)&lt;br /&gt;&lt;br /&gt;##########################################################&lt;br /&gt;## Another Chat Script!&lt;br /&gt;##########################################################&lt;br /&gt;&lt;br /&gt;Well, for those of you who want to make a more advanced chat system here is another script that allows you to enter your name, email, message, and the date! Now that you have finished the above script you shouldn't have very much trouble understanding this one.&lt;br /&gt;&lt;br /&gt;Also, there are a couple of &lt;span style="font-style: italic;"&gt;NEW&lt;/span&gt; functions in this script - don't panic - just stop by &lt;a href="http://www.php.net/" target="_blank" class="postlink"&gt;php.net&lt;/a&gt;, type the name of the function (such as "list()")in the search box, and they will show you what it is and tell you about it. Have a great day!&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;  	  &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt; 	&lt;/tr&gt; 	&lt;tr&gt; 	  &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;7&lt;br/&gt;8&lt;br/&gt;9&lt;br/&gt;10&lt;br/&gt;11&lt;br/&gt;12&lt;br/&gt;13&lt;br/&gt;14&lt;br/&gt;15&lt;br/&gt;16&lt;br/&gt;17&lt;br/&gt;18&lt;br/&gt;19&lt;br/&gt;20&lt;br/&gt;21&lt;br/&gt;22&lt;br/&gt;23&lt;br/&gt;24&lt;br/&gt;25&lt;br/&gt;26&lt;br/&gt;27&lt;br/&gt;28&lt;br/&gt;29&lt;br/&gt;30&lt;br/&gt;31&lt;br/&gt;32&lt;br/&gt;33&lt;br/&gt;34&lt;br/&gt;35&lt;br/&gt;36&lt;br/&gt;37&lt;br/&gt;38&lt;br/&gt;39&lt;br/&gt;40&lt;br/&gt;41&lt;br/&gt;42&lt;br/&gt;43&lt;br/&gt;44&lt;br/&gt;45&lt;br/&gt;46&lt;br/&gt;47&lt;br/&gt;48&lt;br/&gt;49&lt;br/&gt;50&lt;br/&gt;51&lt;br/&gt;52&lt;br/&gt;53&lt;br/&gt;54&lt;br/&gt;55&lt;br/&gt;56&lt;br/&gt;57&lt;br/&gt;58&lt;br/&gt;59&lt;br/&gt;60&lt;br/&gt;61&lt;br/&gt;62&lt;br/&gt;63&lt;br/&gt;64&lt;br/&gt;65&lt;br/&gt;66&lt;br/&gt;67&lt;br/&gt;68&lt;br/&gt;69&lt;br/&gt;70&lt;br/&gt;71&lt;br/&gt;72&lt;br/&gt;73&lt;br/&gt;74&lt;br/&gt;75&lt;br/&gt;76&lt;br/&gt;77&lt;br/&gt;78&lt;br/&gt;79&lt;br/&gt;80&lt;br/&gt;81&lt;br/&gt;82&lt;br/&gt;83&lt;br/&gt;84&lt;br/&gt;85&lt;br/&gt;86&lt;br/&gt;87&lt;br/&gt;88&lt;br/&gt;89&lt;br/&gt;90&lt;br/&gt;91&lt;br/&gt;92&lt;br/&gt;93&lt;br/&gt;94&lt;br/&gt;95&lt;br/&gt;96&lt;br/&gt;97&lt;br/&gt;98&lt;br/&gt;99&lt;br/&gt;100&lt;br/&gt;101&lt;br/&gt;102&lt;br/&gt;103&lt;br/&gt;104&lt;br/&gt;105&lt;br/&gt;106&lt;br/&gt;107&lt;br/&gt;108&lt;br/&gt;109&lt;br/&gt;110&lt;br/&gt;111&lt;br/&gt;112&lt;br/&gt;113&lt;br/&gt;114&lt;br/&gt;&lt;/td&gt; --&gt; 	  &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// lets put our file into an variable ....&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$file &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'chatfile2.txt'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Max size in bytes that you want the Chat file to reach!&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filesize &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;400000&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//////////////////////////////////////////////////////////////////&lt;br /&gt;&lt;br /&gt;/* &lt;br /&gt;This is the code that checks to see if something was "POST" 'ed &lt;br /&gt;and that it is a real message. Also clears out any code that may &lt;br /&gt;have been entered by a user (strip_tags(); ). &lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;if ((isset(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"name"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;])) &amp;amp;&amp;amp; (isset(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"msg"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;])) &amp;amp;&amp;amp; (isset(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"email"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;])) &lt;br /&gt;    &amp;amp;&amp;amp; (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"name"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]!=&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;""&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) &amp;amp;&amp;amp; (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"msg"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]!=&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;""&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) &amp;amp;&amp;amp; (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"email"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]!=&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;""&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)) {&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$email &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;strip_tags&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"email"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]);&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$msg &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;strip_tags&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"msg"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]);&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$name &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;strip_tags&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"name"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]);&lt;br /&gt;    &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$email &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;str_replace&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"|"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;""&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$email&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$msg &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;str_replace&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"|"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;""&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$msg&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$name &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;str_replace&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"|"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;""&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$name&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$date &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;date&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"F j, Y, g:i a"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;/* &lt;br /&gt;    If the code is good then enter it into the file along &lt;br /&gt;    with the other messages from other users. &lt;br /&gt;    Remember that the variable "$file" means the file you are writing too.&lt;br /&gt;    */&lt;br /&gt;    &lt;br /&gt;    &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$content &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"$name|$email|$msg|$date\n"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Add a newline char ("\n") so that each comment is on a new line. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;if (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;filesize&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$file&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) &lt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filesize&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) {&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$handle &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;fopen&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$file&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'a'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;fwrite&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$handle&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$content&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;fclose&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$handle&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;br /&gt;Your Message Has Been Added&lt;br /&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    } else {&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"File Is to Full"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;} &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// End the IF posted loop...&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;//////////////////////////////////////////////////////////////////&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;//////////////////////////////////////////////////////////////////&lt;br /&gt;&lt;br /&gt;/*&lt;br /&gt;This is the code that opens the file and organizes&lt;br /&gt;and prints out the messages that other people left.&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$handle &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;fopen&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$file&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"r"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;br /&gt;if (!(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;filesize&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$file&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) == &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)) {&lt;br /&gt;    &lt;br /&gt;    while (!&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;feof&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$handle&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)) {&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$line &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;fgets&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$handle&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;5096&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;        @list(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$user_name&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$user_email&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$user_msg&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$user_date&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) = &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;explode&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"|"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$line&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;        &lt;br /&gt;        echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'&lt;table border="2"&gt;&lt;tr id="350"&gt;&lt;td&gt;&lt;p&gt;Name: '&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;. &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$user_name&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;.&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'&lt;/td&gt;&lt;td&gt;Email: '&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;. &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$user_email&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;. &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td colspan="2"&gt;Message: '&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;. &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$user_msg&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;.&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td colspan="2"&gt;Date: '&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;.&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$user_date&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;.&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;br /&gt;'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    }&lt;br /&gt;} else { &lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"File is empty"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;fclose&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$handle&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;////////////////////////////////////////////////////////////////////&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/* This is the "FORM" at the bottom of the page used to "Submit" messages to this file */&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'&lt;br /&gt;&lt;br /&gt;&lt;hr /&gt;&lt;hr /&gt;&lt;form action="" method="post"&gt;&lt;table&gt;&lt;br /&gt;&lt;br /&gt;&lt;tr&gt;&lt;td&gt;Your Name:&lt;/td&gt;&lt;td&gt;&lt;input type="text" name="name"&gt;&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;td&gt;Your Email:&lt;/td&gt;&lt;td&gt;&lt;input type="text" name="email"&gt;&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;td&gt;Message:&lt;/td&gt;&lt;td&gt;&lt;textarea name="msg" rows="5" cols="30" maxlength="1000"&gt;Enter Text&lt;/textarea&gt;&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;td&gt;&lt;input type="submit" value="Submit"&gt;&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;br /&gt;&lt;/table&gt;&lt;/form&gt;'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt; 	&lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;You can download both scripts here:&lt;br /&gt;&lt;a href="http://www.learnphpfree.com/lessonfiles/LPF_lesson_19.zip" target="_blank" class="postlink"&gt;Lesson 19 Files&lt;/a&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4889431653894848295-1365640665321734007?l=domyat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://domyat.blogspot.com/feeds/1365640665321734007/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4889431653894848295&amp;postID=1365640665321734007' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4889431653894848295/posts/default/1365640665321734007'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4889431653894848295/posts/default/1365640665321734007'/><link rel='alternate' type='text/html' href='http://domyat.blogspot.com/2008/03/lesson-19-reading-external-files-into.html' title='Lesson 19 - Reading External Files into PHP - Part 4'/><author><name>elawael</name><uri>http://www.blogger.com/profile/11684828293686686914</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4889431653894848295.post-6955927949869382473</id><published>2008-03-31T08:33:00.001-07:00</published><updated>2008-03-31T08:33:58.129-07:00</updated><title type='text'>Lesson 18 - Reading External Files into PHP - Part 3</title><content type='html'>&lt;span class="postbody"&gt;Now that we know how to read data from files into arrays, strings, and variables, lets try writing to files. Writing to files is pretty much the same as reading from them:&lt;br /&gt;&lt;br /&gt;1) First you put the file name/path in a variable so that we can tell the computer what file we want edited (We can it "the file handle").&lt;br /&gt;2) Then we open the file. &lt;br /&gt;3) Now instead of reading from the file we &lt;span style="font-style: italic;"&gt;write&lt;/span&gt; to the file. &lt;br /&gt;4) Finally we close the file.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Open up you text editor (SciTE I hope) and type the following into it. When you are done, upload it to your web server. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;7&lt;br/&gt;8&lt;br/&gt;9&lt;br/&gt;10&lt;br/&gt;11&lt;br/&gt;12&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// 1) Store the file name in a string (this is the file handle).&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filename &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"writetest.txt"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// 2) Open the file&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filehandle &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;fopen&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filename&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'w'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// 3) Write what we want to the file&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;fwrite&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filehandle&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"This goes in the file.\n"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// 4) Close the file&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;fclose&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filehandle&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;(Note: if you &lt;span style="font-style: italic;"&gt;don't&lt;/span&gt; see anything when you browse to the file, it worked. You won't see anything because we don't "echo" or "print" anything in this script; all we do is write to a file.)&lt;br /&gt;&lt;br /&gt;One thing you might notice is that in addition to the script writing to the file, the script also CREATED the file! The "w" command that we put in the fopen function ( fopen($filename, 'w') ) means this to the computer: "Open for writing only; place the file pointer at the beginning of the file and truncate the file to zero length. &lt;span style="font-style: italic;"&gt;If the file does not exist, attempt to create it.&lt;/span&gt;"&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Now if you open "writetest.txt" you will see this in it:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="90%"&gt;&lt;tbody&gt;&lt;tr&gt;    &lt;td&gt;&lt;span class="genmed"&gt;&lt;b&gt;Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt;   &lt;td id="code"&gt;&lt;br /&gt;This goes in the file.&lt;br /&gt;&lt;/td&gt; &lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;And there you have it! I told you it was just as easy to write to files! &lt;img src="http://www.learnphpfree.com/images/smiles/icon_smile.gif" alt="Smile" border="0" /&gt;&lt;br /&gt;&lt;br /&gt;Now lets modify the file to create five lines of text, we will put them on different lines using the "next line" (\n) character:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;7&lt;br/&gt;8&lt;br/&gt;9&lt;br/&gt;10&lt;br/&gt;11&lt;br/&gt;12&lt;br/&gt;13&lt;br/&gt;14&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Put the text we want in the file in a string.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$text &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"This is line one.\nThis is line two.\nThis is line three.\nThis is line four.\nThis is line five.\n"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// 1) Store the file name in a string (this is the file handle).&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filename &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"writetest.txt"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// 2) Open the file&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filehandle &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;fopen&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filename&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'w'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// 3) Write what we want to the file&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;fwrite&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filehandle&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$text&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// 4) Close the file&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;fclose&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filehandle&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;Now after running the file you will see this in writetext.txt:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="90%"&gt;&lt;tbody&gt;&lt;tr&gt;    &lt;td&gt;&lt;span class="genmed"&gt;&lt;b&gt;Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt;   &lt;td id="code"&gt;&lt;br /&gt;This is line one.&lt;br /&gt;This is line two.&lt;br /&gt;This is line three.&lt;br /&gt;This is line four.&lt;br /&gt;This is line five.&lt;br /&gt;&lt;/td&gt; &lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;Peace of cake, huh? &lt;img src="http://www.learnphpfree.com/images/smiles/icon_cool.gif" alt="Cool" border="0" /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;To finish off our file lets delete the comments in the code (you can keep them if you want) and add a couple of error checking functions - just so you learn to code properly. First lets add a "die" command to the &lt;span style="font-style: italic;"&gt;fopen&lt;/span&gt; function:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;7&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$text &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"This is line one.\nThis is line two.\nThis is line three.\nThis is line four.\nThis is line five.\n"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filename &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"writetest.txt"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filehandle &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;fopen&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filename&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'w'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) or die(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'Could not open the file'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;fwrite&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filehandle&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$text&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;fclose&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filehandle&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;The &lt;span style="font-style: italic;"&gt;or die&lt;/span&gt; command just means:&lt;br /&gt;&lt;span style="font-style: italic;"&gt;If there is an error: stop the script and display [i]this&lt;/span&gt; message instead of a cryptic PHP error message.[/i]&lt;br /&gt;Feel free to change "Could not open the file" to anything you want the error to say. You can test it by putting an error like this in the code:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="90%"&gt;&lt;tbody&gt;&lt;tr&gt;    &lt;td&gt;&lt;span class="genmed"&gt;&lt;b&gt;Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt;   &lt;td id="code"&gt;&lt;br /&gt;$filehandle = fopen($filename22222, 'w') or die('Could not open the file');&lt;br /&gt;&lt;/td&gt; &lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Second lets add a message that lets us know that everything went all right. (First fix the error you just made &lt;img src="http://www.learnphpfree.com/images/smiles/icon_wink.gif" alt="Wink" border="0" /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;7&lt;br/&gt;8&lt;br/&gt;9&lt;br/&gt;10&lt;br/&gt;11&lt;br/&gt;12&lt;br/&gt;13&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$text &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"This is line one.\nThis is line two.\nThis is line three.\nThis is line four.\nThis is line five.\n"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filename &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"writetest.txt"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filehandle &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;fopen&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filename&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'w'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) or die(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'Could not open the file'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;br /&gt;if (!&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;fwrite&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filehandle&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$text&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)) {&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Could Not write to the file!"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;} else {&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Wrote the following to the file:&lt;br /&gt;$text"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;fclose&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filehandle&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;For those of you who don't know; this is an &lt;span style="font-style: italic;"&gt;if&lt;/span&gt; statement. Lets take it line by line to make it easier to understand:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;if (!&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;fwrite&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filehandle&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$text&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)) {&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Could Not write to the file!"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;In english it reads:&lt;br /&gt;&lt;/span&gt;&lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="90%"&gt;&lt;tbody&gt;&lt;tr&gt;    &lt;td&gt;&lt;span class="genmed"&gt;&lt;b&gt;Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt;   &lt;td id="code"&gt;&lt;br /&gt;if (you [b]cannont[/b] write (!fwrite) the value of "$text" to "writetest.txt") { &lt;br /&gt;    print "Could Not write to the file!"&lt;br /&gt;&lt;/td&gt; &lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;span class="postbody"&gt;&lt;br /&gt;Basically, if something goes wrong and you CANNOT write to the file, tell the user.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Here is the next part that will run &lt;span style="font-style: italic;"&gt;if&lt;/span&gt; the first part of the loop is &lt;span style="font-weight: bold;"&gt;false&lt;/span&gt;:&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;} else {&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Wrote the following to the file:&lt;br /&gt;$text"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;} &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;This &lt;span style="font-style: italic;"&gt;else&lt;/span&gt; statement will ONLY run if the first part ("if could not write") is false. If this does run then that means that the script COULD write to the file! Along with letting the user know that everything is OK, we print out the value of what we put in the file ($text).&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;##################################################&lt;br /&gt;## Checking Files&lt;br /&gt;##################################################&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Now lets practice with some of the other functions made for files:&lt;br /&gt;&lt;br /&gt;is_file() - returns True/False indicating whether the specified file is a regular file&lt;br /&gt;is_executable() - returns True/False indicating whether the specified file is executable&lt;br /&gt;is_readable()- returns True/False indicating whether the specified file is readable&lt;br /&gt;is_writable()- returns True/False indicating whether the specified file is writable&lt;br /&gt;filesize() - gets size of file&lt;br /&gt;filemtime() - gets last modification time of file&lt;br /&gt;filetype() - gets file type &lt;br /&gt;&lt;br /&gt;(Note: you can find ALL of the functions for files at &lt;a href="http://us3.php.net/manual/en/function.file.php" target="_blank" class="postlink"&gt;php.net&lt;/a&gt;)&lt;br /&gt;&lt;br /&gt;Lets put each one to use in a new script; type this into you editor:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;7&lt;br/&gt;8&lt;br/&gt;9&lt;br/&gt;10&lt;br/&gt;11&lt;br/&gt;12&lt;br/&gt;13&lt;br/&gt;14&lt;br/&gt;15&lt;br/&gt;16&lt;br/&gt;17&lt;br/&gt;18&lt;br/&gt;19&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;br /&gt;$filename &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"writetest.txt"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;if (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;is_file&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filename&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)) { echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"$filename is a File!&lt;br /&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; }&lt;br /&gt;&lt;br /&gt;if (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;is_executable&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filename&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)) { echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"$filename is executable!&lt;br /&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; }&lt;br /&gt;&lt;br /&gt;if (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;is_readable&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filename&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)) { echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"$filename is readable!&lt;br /&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; }&lt;br /&gt;&lt;br /&gt;if (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;is_writable&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filename&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)) { echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"$filename is writable!&lt;br /&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; }&lt;br /&gt;&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;" $filename is "&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;. &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;filesize&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filename&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;). &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;" bytes&lt;br /&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"$filename was last modified: " &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;. &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;date &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"F d Y H:i:s."&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;filemtime&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filename&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)). &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;br /&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"$filename is a "&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;. &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;filetype&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filename&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;). &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;" file&lt;br /&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;Notice that every function except for &lt;span style="font-style: italic;"&gt;is_executable&lt;/span&gt; was &lt;span style="font-style: italic;"&gt;true&lt;/span&gt;. That is because ".txt" files are just plain text files - they are not programs.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;###############################################&lt;br /&gt;## Extra Information about the &lt;span style="font-style: italic;"&gt;echo&lt;/span&gt; statements&lt;br /&gt;###############################################&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Another thing that might throw you off are the periods ( . ) in some of the &lt;span style="font-style: italic;"&gt;echo&lt;/span&gt; statements. Such as:&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;" $filename is "&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;. &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;filesize&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filename&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;). &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;" bytes&lt;br /&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;These periods are a way to &lt;span style="font-style: italic;"&gt;add&lt;/span&gt; different kinds of things to an echo. As you know a normal echo looks like this:&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Hello World"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;You can also echo functions like this:&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;filetype&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filename&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;); &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;However, when you want to echo the results of a function &lt;span style="font-weight: bold;"&gt;within&lt;/span&gt; a sentence you can't do this:&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Hello World, filetype($filename)"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;All you would see is "Hello World, filetype(writetest.txt)" if you ran it. And if you tried to end the text ( put a closing ")and &lt;span style="font-style: italic;"&gt;then&lt;/span&gt; put in the function you would get a parse error:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Hello World" &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;filetype&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filename&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// gives you a parse error!!! &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;This is where ( . ) enters in, they tell the computer that there is more coming in the echo command:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"$filename is "&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;. &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;filesize&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filename&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;). &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;" bytes&lt;br /&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;In English this code would read:&lt;br /&gt;&lt;/span&gt;&lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="90%"&gt;&lt;tbody&gt;&lt;tr&gt;    &lt;td&gt;&lt;span class="genmed"&gt;&lt;b&gt;Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt;   &lt;td id="code"&gt;&lt;br /&gt;print {{Start of Text}} (the value of "$filename") is {{End of Text}} plus ( . ) (print the size of "$filename") plus ( . ) {{Start of Text}} bytes&lt;br /&gt; {{End of Text}};&lt;br /&gt;&lt;/td&gt; &lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;span class="postbody"&gt;&lt;br /&gt; &lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4889431653894848295-6955927949869382473?l=domyat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://domyat.blogspot.com/feeds/6955927949869382473/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4889431653894848295&amp;postID=6955927949869382473' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4889431653894848295/posts/default/6955927949869382473'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4889431653894848295/posts/default/6955927949869382473'/><link rel='alternate' type='text/html' href='http://domyat.blogspot.com/2008/03/lesson-18-reading-external-files-into.html' title='Lesson 18 - Reading External Files into PHP - Part 3'/><author><name>elawael</name><uri>http://www.blogger.com/profile/11684828293686686914</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4889431653894848295.post-4247898179271952136</id><published>2008-03-31T08:32:00.002-07:00</published><updated>2008-03-31T08:33:16.031-07:00</updated><title type='text'>Lesson 17 - Reading External Files into PHP - Part 2</title><content type='html'>&lt;table class="forumline" border="0" cellpadding="3" cellspacing="1" width="100%"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class="row1" height="28" valign="top" width="100%"&gt;&lt;table border="0" cellpadding="0" cellspacing="0" width="100%"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td colspan="2"&gt;&lt;span class="postbody"&gt;Now lets put what we learned about the explode() function and arrays into practice parsing (dealing with) files. Lets make a file called "file.txt" and fill it with at least 5 lines of non-sense. Open up SciTE or Notepad and type the following:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="90%"&gt;&lt;tbody&gt;&lt;tr&gt;    &lt;td&gt;&lt;span class="genmed"&gt;&lt;b&gt;Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt;   &lt;td id="code"&gt;&lt;br /&gt;This is line 1&lt;br /&gt;This is line 2&lt;br /&gt;This is line   ...uh... (what is after 2?)&lt;br /&gt;anyways, this is the next line&lt;br /&gt;And this is the last line!&lt;br /&gt;&lt;/td&gt; &lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;span class="postbody"&gt;&lt;br /&gt;Save the file and up load it to your web server. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Make an new make a new file called "filetoarray.php". After you save it type the following into it:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;7&lt;br/&gt;8&lt;br/&gt;9&lt;br/&gt;10&lt;br/&gt;11&lt;br/&gt;12&lt;br/&gt;13&lt;br/&gt;14&lt;br/&gt;15&lt;br/&gt;16&lt;br/&gt;17&lt;br/&gt;18&lt;br/&gt;19&lt;br/&gt;20&lt;br/&gt;21&lt;br/&gt;22&lt;br/&gt;23&lt;br/&gt;24&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Store the file name in a string.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filename &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"file.txt"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Read file into array&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$contents &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;file&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filename&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"there are &lt;b&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;. &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;count&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$contents&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;). &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;/b&gt; lines in this file. Here is what he array looks like now:&lt;br /&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;print_r&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$contents&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;hr /&gt;&lt;b&gt;Below are the lines in the file after they were \"shuffled\":&lt;/b&gt;&lt;br /&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;shuffle&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$contents&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Loop through the array and print each line to the screen.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;foreach (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$contents &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;as &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$line&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)&lt;br /&gt;{&lt;br /&gt;   echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$line&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;. &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;br /&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;hr /&gt;Now the SHUFFLED array looks like this:&lt;br /&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;print_r&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$contents&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;Then save it and upload it to the same directory as "file.txt".&lt;br /&gt;&lt;br /&gt;After you run the file you should see two parts to the script. First is the Number of lines that are in the file and a print-out of what array element each line is in. Second you should see the lines you typed in file.txt showing up in a &lt;span style="font-style: italic;"&gt;random&lt;/span&gt; order every time you refresh the page, with the print-out of what array element they are below them. So lets go over them!&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Store the file name in a string.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filename &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"file.txt"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;In this first part of the code we store the name of a file in a variable.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Read file into array&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$contents &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;file&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filename&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;); &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;Next we use the "file" function to read &lt;span style="font-style: italic;"&gt;every&lt;/span&gt; line out of "file.txt" into and array called "$contents". Every line will be a different &lt;span style="font-weight: bold;"&gt;element&lt;/span&gt; it the array. For example, line one will be the first element in the array:&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;Array ([&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;] =&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;This is line 1&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//Remember arrays start at "0" and go up for each element. &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;Line two will be the &lt;span style="font-style: italic;"&gt;second&lt;/span&gt; element in the array&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;Array ([&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;] =&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;This is line 2&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;); &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;And so on....&lt;br /&gt;Each new line will be put into a new element of the array. Since my file.txt has five lines there will be five elements in the array. (0,1,2,3,4 because arrays start at 0)&lt;br /&gt;&lt;br /&gt;Next we will use the count() function to &lt;span style="font-style: italic;"&gt;count&lt;/span&gt; how many elements are in the array:&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"there are &lt;b&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;. &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;count&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$contents&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;). &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;/b&gt; lines in this file. Here is what he array looks like now:&lt;br /&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;(Note: Remember, there are the same number of lines in the file as there are elements in the array so counting the elements in the array will tell us the number of lines in the file. Confused yet?)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;hr /&gt;&lt;b&gt;Below are the lines in the file after they were \"shuffled\":&lt;/b&gt;&lt;br /&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;shuffle&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$contents&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;); &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;In the above code we then use the shuffle() function to randomly &lt;span style="font-style: italic;"&gt;shuffle&lt;/span&gt; the elements in the array. So element "0" might end up as element "3" and so on. End the end we will still have five elements in the array... they'll just be in different places!&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Last, we use a &lt;span style="font-style: italic;"&gt;foreach&lt;/span&gt; loop to go through each element in the array and print out the line:&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;7&lt;br/&gt;8&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Loop through the array and print each line to the screen.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;foreach (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$contents &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;as &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$line&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)&lt;br /&gt;{&lt;br /&gt;   echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$line&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;. &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;br /&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;hr /&gt;Now the SHUFFLED array looks like this:&lt;br /&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;print_r&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$contents&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;); &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;We end by using the print_r function to show you what the array looks like &lt;span style="font-style: italic;"&gt;after&lt;/span&gt; it has been shuffled.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;##################################################################&lt;br /&gt;&lt;br /&gt;Now lets make something useful out of this....I know! how about a random quote?&lt;br /&gt;(Like the one you see at the bottom of this page!)&lt;br /&gt;Change the code in "filetoarray.php" to this:&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;7&lt;br/&gt;8&lt;br/&gt;9&lt;br/&gt;10&lt;br/&gt;11&lt;br/&gt;12&lt;br/&gt;13&lt;br/&gt;14&lt;br/&gt;15&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Store the file name in a string.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filename &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"file.txt"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Read file into array&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$contents &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;file&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filename&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Shuffle the elements to make the array random&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;shuffle&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$contents&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Print out the first element.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$contents&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;];&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;This is pretty simple to follow so I am just going to review some of it. After we have read each line into an array called "$contents" we just shuffle the arrays elements to make them random and print out the first element. (Which would be one of the lines in the file.)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;#######################################################&lt;br /&gt;&lt;br /&gt;You could also use something like this to choose a random banner or affiliate! So that is your home work - I want you to try to figure out how you could make a random image appear. I'll give you a major hint, &lt;img src="http://www.learnphpfree.com/images/smiles/icon_cool.gif" alt="Cool" border="0" /&gt; change "file.txt" to contain a new HTML image tag (&lt;img&gt;) for each line!&lt;/span&gt;&lt;span class="gensmall"&gt;&lt;/span&gt;&lt;/td&gt;    &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;   &lt;td class="row1" align="left" valign="middle" width="150"&gt;&lt;span class="nav"&gt;&lt;a href="http://www.learnphpfree.com/lesson-17--reading-external-files-into-php--part-2-vt51.html#top" class="nav"&gt;Back to top&lt;/a&gt;&lt;/span&gt;&lt;/td&gt;   &lt;td class="row1" height="28" nowrap="nowrap" valign="bottom" width="100%"&gt;&lt;table border="0" cellpadding="0" cellspacing="0" height="18" width="18"&gt;    &lt;tbody&gt;&lt;tr&gt;     &lt;td nowrap="nowrap" valign="middle"&gt;&lt;a href="http://www.learnphpfree.com/profile.php?mode=viewprofile&amp;amp;u=3"&gt;&lt;img src="http://www.learnphpfree.com/templates/subSilver/images/lang_english/icon_profile.gif" alt="View user's profile" title="View user's profile" border="0" /&gt;&lt;/a&gt;  &lt;a href="http://www.learnphpfree.com/privmsg.php?mode=post&amp;amp;u=3"&gt;&lt;img src="http://www.learnphpfree.com/templates/subSilver/images/lang_english/icon_pm.gif" alt="Send private message" title="Send private message" border="0" /&gt;&lt;/a&gt;      &lt;script language="JavaScript" type="text/javascript"&gt;&lt;!--   if ( navigator.userAgent.toLowerCase().indexOf('mozilla') != -1 &amp;&amp; navigator.userAgent.indexOf('5.') == -1 &amp;&amp; navigator.userAgent.indexOf('6.') == -1 )   document.write(' ');  else   document.write('&lt;/td&gt;&lt;td&gt; &lt;/td&gt;&lt;td valign="top" nowrap="nowrap"&gt;&lt;div style="position:relative"&gt;&lt;div style="position:absolute"&gt;&lt;/div&gt;&lt;div style="position:absolute;left:3px;top:-1px"&gt;&lt;/div&gt;&lt;/div&gt;');      //--&gt;&lt;/script&gt;&lt;/td&gt;&lt;td&gt; &lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4889431653894848295-4247898179271952136?l=domyat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://domyat.blogspot.com/feeds/4247898179271952136/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4889431653894848295&amp;postID=4247898179271952136' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4889431653894848295/posts/default/4247898179271952136'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4889431653894848295/posts/default/4247898179271952136'/><link rel='alternate' type='text/html' href='http://domyat.blogspot.com/2008/03/lesson-17-reading-external-files-into.html' title='Lesson 17 - Reading External Files into PHP - Part 2'/><author><name>elawael</name><uri>http://www.blogger.com/profile/11684828293686686914</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4889431653894848295.post-5510875132458954237</id><published>2008-03-31T08:32:00.001-07:00</published><updated>2008-03-31T08:32:41.289-07:00</updated><title type='text'>Lesson 16 - Reading External Files into PHP</title><content type='html'>&lt;span class="postbody"&gt;Now it's time for us to learn how to use PHP's file API to create, edit, and destroy files through PHP.&lt;br /&gt;&lt;br /&gt;"One of the most basic things you can do with any programming language is create and manipulate data structures. These structures may be transient - in-memory variables like arrays or objects - or more permanent - disk-based entities like files or database tables; however, the ability to create, modify and erase them in a convenient and consistent manner is of paramount importance to any programmer.&lt;br /&gt;&lt;br /&gt;Like all widely used programming languages, PHP has the very useful ability to read data from, and write data to, files on the system. But the language doesn't just stop there - PHP comes with a full-featured file-and-directory-manipulation API that allows you (among other things) to view and modify file attributes, read and list directory contents, alter file permissions, retrieve file contents into a variety of native data structures, and search for files based on specific patterns. This file manipulation API is both powerful and flexible - two characteristics that will endear it to any developer who's ever had to work with file manipulation commands." -&lt;a href="http://www.melonfire.com/" target="_blank" class="postlink"&gt;Melonfire&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;fread&lt;br /&gt;Start by making a file in the same folder as your php scripts. Name the file "file.txt" and write something in it like:&lt;br /&gt;&lt;/span&gt;&lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="90%"&gt;&lt;tbody&gt;&lt;tr&gt;    &lt;td&gt;&lt;span class="genmed"&gt;&lt;b&gt;Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt;   &lt;td id="code"&gt;&lt;br /&gt;&lt;br /&gt;If you can read this my script works!&lt;br /&gt;Or maybe it doesn't...&lt;br /&gt;That's it!&lt;br /&gt;he computer is just guessing what is in the file...&lt;br /&gt;&lt;br /&gt;&lt;/td&gt; &lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;span class="postbody"&gt; &lt;br /&gt;(Note: It is important that you type at least 4 lines worth of text.)&lt;br /&gt;Then close the file and make a new file named "fileopen.php" and type this into it:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;7&lt;br/&gt;8&lt;br/&gt;9&lt;br/&gt;10&lt;br/&gt;11&lt;br/&gt;12&lt;br/&gt;13&lt;br/&gt;14&lt;br/&gt;15&lt;br/&gt;16&lt;br/&gt;17&lt;br/&gt;18&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Store the file name in a string.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filename &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"file.txt"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Open the file.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filehandle &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;fopen&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filename&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"r"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Read the files contents.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$contents &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;fread&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filehandle&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;filesize&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filename&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;));&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Close file.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;fclose&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filehandle&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Echo the files contents&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$contents&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;When you run the script you will see a blank screen with the text "If you can read this my script works!" on it. If you get an error double check your code and make sure that "file.txt" and "fileopen.php" are in the same place.&lt;br /&gt;&lt;br /&gt;Now to explain what the script does:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Store the file name in a string.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filename &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"file.txt"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;Here we start by putting the name of the file we want in a string.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Open the file.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filehandle &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;fopen&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filename&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"r"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;); &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;Next we create a "file handle" which is kind of hard to explain, but basically it is how the computer now can remember the file. It is a "handle" that can be used to tell the computer what your referring too. I'm sure you've herd the saying "What's your Handle?" in street/gangster movies. I'm sure your probably wondering what the "r" means, it is the type of mode to open the file in - "READ" mode. For all modes see the bottom of the page.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Read the files contents.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$contents &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;fread&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filehandle&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;filesize&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filename&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)); &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;Here we read (fread) the contents of the file into a string. Notice that there are two different parts to fread(). The first is the handle we will use to tell the script what file we want to open. The next is the number of bytes to be read. You could put a number like this:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Read the files contents.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$contents &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;fread&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filehandle&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;4068&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;); &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;Where the script will stop reading the file when it gets to 4068 bytes or the end of the script. (Which ever comes first)&lt;br /&gt;&lt;br /&gt;However I find it easier to just tell the script to get as many bytes as there are:&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;filesize&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filename&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Close file.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;fclose&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filehandle&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Echo the files contents&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$contents&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;Last we close the file and destroy the file handle. Then print the files contents to the screen. You don't &lt;span style="font-style: italic;"&gt;have&lt;/span&gt; to close the file handle, but your scripts will end up with a lot of open files if you don't...&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;readfile&lt;br /&gt;&lt;br /&gt;The simplest way to read a file into php and output it to the screen is to use the readfile() function.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;7&lt;br/&gt;8&lt;br/&gt;9&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Store the file name in a string.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filename &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"file.txt"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Prints the files contents.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;readfile&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filename&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;fgets&lt;br /&gt;Here is another way to open a file and get the contents. "fgets" gets &lt;span style="font-style: italic;"&gt;one&lt;/span&gt; line out of the file specified by the file handle. &lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;7&lt;br/&gt;8&lt;br/&gt;9&lt;br/&gt;10&lt;br/&gt;11&lt;br/&gt;12&lt;br/&gt;13&lt;br/&gt;14&lt;br/&gt;15&lt;br/&gt;16&lt;br/&gt;17&lt;br/&gt;18&lt;br/&gt;19&lt;br/&gt;20&lt;br/&gt;21&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Store the file name in a string.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filename &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"file.txt"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Open the file.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filehandle &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;fopen&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filename&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"r"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Read the file line by line into a string.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;while (!&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;feof&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filehandle&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;))&lt;br /&gt;{&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$contents &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;.= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;fgets&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filehandle&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Close file.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;fclose&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filehandle&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Echo the files contents&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$contents&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;The first part specifies the file to open and creates a "handle" for it:&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Store the file name in a string.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filename &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"file.txt"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Open the file.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filehandle &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;fopen&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filename&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"r"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;); &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;Next we need to recal that lesson about loops to understand the "while" loop:&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Read the file line by line into a string.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;while (!&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;feof&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;($&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filehandle&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;))&lt;br /&gt;{&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$contents &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;.= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;fgets&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$fh&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;} &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;Basicaly, in human language it says:&lt;br /&gt;&lt;/span&gt;&lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="90%"&gt;&lt;tbody&gt;&lt;tr&gt;    &lt;td&gt;&lt;span class="genmed"&gt;&lt;b&gt;Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt;   &lt;td id="code"&gt;&lt;br /&gt;&lt;br /&gt;While it is not the END OF THE FILE (feof: FILE END OF) {&lt;br /&gt;    Get a line out of the file and add it to the string $contents. &lt;br /&gt;    ($contents .= fgets($fh))&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/td&gt; &lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;span class="postbody"&gt;&lt;br /&gt;Note: the little dot in front of the "=" sign means "add to". If the code was:&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$contents &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;fgets&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$fh&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;); &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;Then every time the while loop ran it would &lt;span style="font-style: italic;"&gt;over write&lt;/span&gt; the old value of $contents with a new value. But we don't want it to do that! We want it to &lt;span style="font-style: italic;"&gt;add&lt;/span&gt; the new value to $contents.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;File()&lt;br /&gt;&lt;br /&gt;Last I want to show you how to read a file into an array! If you haven't read the lesson on arrays you need to do so now! (I also recommend that you open "file.txt" and change the text because it is getting old....)&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;7&lt;br/&gt;8&lt;br/&gt;9&lt;br/&gt;10&lt;br/&gt;11&lt;br/&gt;12&lt;br/&gt;13&lt;br/&gt;14&lt;br/&gt;15&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Store the file name in a string.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filename &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"file.txt"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Read file into array&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$contents &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;file&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$filename&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Loop through the array and print each line to the screen.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;foreach (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$contents &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;as &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$line&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)&lt;br /&gt;{&lt;br /&gt;   echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$line&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;Ok, this one is the hardest, but don't worry we'll get it down!&lt;br /&gt;In English the foreach loop looks like this:&lt;br /&gt;&lt;/span&gt;&lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="90%"&gt;&lt;tbody&gt;&lt;tr&gt;    &lt;td&gt;&lt;span class="genmed"&gt;&lt;b&gt;Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt;   &lt;td id="code"&gt;&lt;br /&gt;&lt;br /&gt;For every element/line in the array "$contents": put that element into a variable called "$line" {&lt;br /&gt;    Then print the value of "$line" to the screen.&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/td&gt; &lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Hope this lesson helped you to understand how to read files into PHP Scripts Next lesson I will show you how to do more advanced things with files!&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;MODES&lt;br /&gt;&lt;br /&gt;Here are all of the modes for the fopen() function:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;mode Description&lt;br /&gt;'r' Open for reading only; place the file pointer at the beginning of the file.&lt;br /&gt;'r+' Open for reading and writing; place the file pointer at the beginning of the file.&lt;br /&gt;'w' Open for writing only; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.&lt;br /&gt;'w+' Open for reading and writing; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.&lt;br /&gt;'a' Open for writing only; place the file pointer at the end of the file. If the file does not exist, attempt to create it.&lt;br /&gt;'a+' Open for reading and writing; place the file pointer at the end of the file. If the file does not exist, attempt to create it.&lt;br /&gt;'x' Create and open for writing only; place the file pointer at the beginning of the file. If the file already exists, the fopen() call will fail by returning FALSE and generating an error of level E_WARNING. If the file does not exist, attempt to create it. This is equivalent to specifying O_EXCL|O_CREAT flags for the underlying open(2) system call. This option is supported in PHP 4.3.2 and later, and only works for local files.&lt;br /&gt;'x+' Create and open for reading and writing; place the file pointer at the beginning of the file. If the file already exists, the fopen() call will fail by returning FALSE and generating an error of level E_WARNING. If the file does not exist, attempt to create it. This is equivalent to specifying O_EXCL|O_CREAT flags for the underlying open(2) system call. This option is supported in PHP 4.3.2 and later, and only works for local files.&lt;br /&gt; &lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4889431653894848295-5510875132458954237?l=domyat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://domyat.blogspot.com/feeds/5510875132458954237/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4889431653894848295&amp;postID=5510875132458954237' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4889431653894848295/posts/default/5510875132458954237'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4889431653894848295/posts/default/5510875132458954237'/><link rel='alternate' type='text/html' href='http://domyat.blogspot.com/2008/03/lesson-16-reading-external-files-into.html' title='Lesson 16 - Reading External Files into PHP'/><author><name>elawael</name><uri>http://www.blogger.com/profile/11684828293686686914</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4889431653894848295.post-717068628890886055</id><published>2008-03-31T08:31:00.001-07:00</published><updated>2008-03-31T08:31:58.567-07:00</updated><title type='text'>Lesson 15 - Explode</title><content type='html'>&lt;span class="postbody"&gt;As you keep advancing in your knowledge of PHP you will find that you need to break-up large strings every now and then - enter the &lt;span style="font-weight: bold;"&gt;explode()&lt;/span&gt; function.&lt;br /&gt;&lt;br /&gt;explode(); - Splits a string by string (Turns a string into an array made up of the different values.)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$fullname  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"John Doe"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$name &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;explode&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;" "&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$fullname&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$name&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]; &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// 'John'&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$name&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]; &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// 'Doe'&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;This is very useful if you have several different values you need hidden in one string.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;7&lt;br/&gt;8&lt;br/&gt;9&lt;br/&gt;10&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$list_names  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"name1 name2 name3 name4 name5 name6"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$names &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;explode&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;" "&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$list_names&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$names&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]; &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// name1&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$names&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]; &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// name2&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$names&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;2&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]; &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// name3&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$names&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;3&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]; &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// name4&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$names&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;4&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]; &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// name5&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$names&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;5&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]; &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// name6&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;_____________________________________________________________________&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Advanced "limit" parameter examples:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$string &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'one|two|three|four'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;print_r&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;explode&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'|'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$string&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;2&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;));      &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//Notice the "2"&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The above example will output:&lt;br /&gt;&lt;br /&gt;Array&lt;br /&gt;(&lt;br /&gt;    [0] =&gt; one&lt;br /&gt;    [1] =&gt; two|three|four&lt;br /&gt;)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;As you will notice, it only split the $string into 2 pieces and then stopped after the first "|". This is because the number of times it should "explode" the string was set to "2" in the above code. This is just an optional value you can include in the explode command to stop it after a certain number of splits.&lt;br /&gt;&lt;br /&gt;_____________________________________________________________________&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$str &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'one|two|three|four'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;print_r&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;explode&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'|'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$str&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, -&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)); &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// negative limit (since PHP 5.1)&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt; &lt;br /&gt;&lt;br /&gt;The above example will output:&lt;br /&gt;&lt;br /&gt;Array&lt;br /&gt;(&lt;br /&gt;    [0] =&gt; one&lt;br /&gt;    [1] =&gt; two&lt;br /&gt;    [2] =&gt; three&lt;br /&gt;)&lt;br /&gt;&lt;br /&gt;Now it split the $string into three pieces and then left the last value off. This is because the number of times it should "explode" the string was set to "-1", which means it should explode everything in the string but the last "split" value (which is deleted). This is just an optional value you can include in the explode command to stop it after a certain number of splits.&lt;br /&gt;_____________________________________________________________________&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Here is a real-life example of what a line might look like in a file:&lt;br /&gt;&lt;/span&gt;&lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="90%"&gt;&lt;tbody&gt;&lt;tr&gt;    &lt;td&gt;&lt;span class="genmed"&gt;&lt;b&gt;Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt;   &lt;td id="code"&gt;&lt;br /&gt;2006:David:learnphpfree:what an awsome site!&lt;br /&gt;&lt;/td&gt; &lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;span class="postbody"&gt;&lt;br /&gt;We can take that and &lt;span style="font-weight: bold;"&gt;explode&lt;/span&gt; it so that we can use the pieces:&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;7&lt;br/&gt;8&lt;br/&gt;9&lt;br/&gt;10&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$file_contents &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"2006:David:learnphpfree:what an awsome site!"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$contents &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;explode&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;':'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$file_contents&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Date: $contents[0]"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;              &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//prints "Date: 2006"&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Name: $contents[1]"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;              &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//prints "Name: David"&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Website: http://www.$contents[2].com"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//prints "Website: http://www.learnphpfree.com"&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Comment: $contents[3]"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;           &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//prints "Comment: what an awsome site!"&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;you can find more information at:&lt;br /&gt;&lt;a href="http://us2.php.net/manual/en/function.explode.php" target="_blank" class="postlink"&gt;php.net&lt;/a&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4889431653894848295-717068628890886055?l=domyat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://domyat.blogspot.com/feeds/717068628890886055/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4889431653894848295&amp;postID=717068628890886055' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4889431653894848295/posts/default/717068628890886055'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4889431653894848295/posts/default/717068628890886055'/><link rel='alternate' type='text/html' href='http://domyat.blogspot.com/2008/03/lesson-15-explode.html' title='Lesson 15 - Explode'/><author><name>elawael</name><uri>http://www.blogger.com/profile/11684828293686686914</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4889431653894848295.post-7266336364665054836</id><published>2008-03-31T08:30:00.000-07:00</published><updated>2008-03-31T08:31:17.581-07:00</updated><title type='text'>Lesson 14 - Arrays</title><content type='html'>&lt;span class="postbody"&gt;&lt;span style="font-weight: bold;"&gt;Arrays&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;I believe that the best way to learn something is to do it. There are several different arrays in the following paragraphs. I want you to look over them try to understand how they work. Then at the bottom of this lesson you can download a copy of this page to run on your own server. Try changing the arrays and making up new ones. I guarantee you will learn arrays very fast!&lt;br /&gt;&lt;br /&gt;If you ever have any questions please feel free to post them in the &lt;a href="http://www.learnphpfree.com/forum/" target="_blank" class="postlink"&gt;forums&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$numbers &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= array(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;2&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;3&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;4&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;5&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;print_r&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$numbers&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt; &lt;br /&gt;In this array we make an array named &lt;span style="font-weight: bold;"&gt;$numbers&lt;/span&gt; and put the following values in it: 1, 2, 3, 4, and 5,&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$labels &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;range&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;5&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;10&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;print_r&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$labels&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt; &lt;br /&gt;In this array we make an array named &lt;span style="font-weight: bold;"&gt;$labels&lt;/span&gt; and put all of the values between 5 and 10 in it.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$people &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= array(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"joe"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"bob"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"sarah"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;print_r&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$people&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt; &lt;br /&gt;First we define an array and call it &lt;span style="font-weight: bold;"&gt;$people&lt;/span&gt;, then we put "joe", "bob", and "sarah" in it.&lt;br /&gt;&lt;br /&gt;Number "1" would print out "bob":&lt;br /&gt;&lt;/span&gt;&lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="90%"&gt;&lt;tbody&gt;&lt;tr&gt;    &lt;td&gt;&lt;span class="genmed"&gt;&lt;b&gt;Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt;   &lt;td id="code"&gt;&lt;br /&gt;echo $people[1];&lt;br /&gt;&lt;/td&gt; &lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$people&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;];&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt; &lt;br /&gt;(Remember that arrays start with ZERO as the first value.)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$fruit &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= array(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"apple"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"banana"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"watermelon"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;print_r&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$fruit&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Here we make an array named &lt;span style="font-weight: bold;"&gt;$fruit&lt;/span&gt; AND:&lt;br /&gt;put "apple" in the first array value&lt;br /&gt;put "banana" in the second array value&lt;br /&gt;put "watermelon" in the third array value&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$fruit &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;explode&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;","&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"apple,banana,watermelon"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;print_r&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$fruit&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt; &lt;br /&gt;&lt;br /&gt;Here we take a sentence (apple,banana,watermelon) and "explode" it. &lt;br /&gt;In other words we split it by the character "&lt;span style="font-weight: bold;"&gt;,&lt;/span&gt;". So everywhere explode&lt;br /&gt;finds a "&lt;span style="font-weight: bold;"&gt;,&lt;/span&gt;" it will split the string. Then the three pieces are put into&lt;br /&gt;an array named &lt;span style="font-weight: bold;"&gt;$fruit&lt;/span&gt;. In the next lesson we will talk more about &lt;span style="font-weight: bold;"&gt;explode&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$fruit_weight &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= array(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"apple" &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;35&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"banana" &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;29&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"watermelon" &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;25&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;print_r&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$fruit_weight&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt; &lt;br /&gt;&lt;br /&gt;Here an array named &lt;span style="font-weight: bold;"&gt;$fruit_weight&lt;/span&gt; is created. Then the array's variables are named something specific like "apple" and given a value. This is important to note - you don't have to except the default 0,1,2,3,4,etc.. array variables: YOU CAN NAME THEM YOURSELF!&lt;br /&gt;(No more &lt;span style="font-weight: bold;"&gt;$array[2]&lt;/span&gt; now you can name something &lt;span style="font-weight: bold;"&gt;$array[yourname]&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$friends &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= array(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"John" &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&gt; &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'Happy'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Sue" &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&gt; &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'Fun'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Sam" &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&gt; &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Sad"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;print_r&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$friends&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt; &lt;br /&gt;&lt;br /&gt;Here is an array where you make all of the variables your friends names and then make their values their moods. Notice that for the last intry ("Sam" =&gt; "Sad")I put double quotaition marks insted of single quotaition marks on the value. Either way it dosen't make any difference.&lt;br /&gt;&lt;br /&gt;Now lets print each value:&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$friends&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'John'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]. &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;""&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$friends&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;Sue&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]. &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;""&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$friends&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Sam"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]. &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;""&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt; &lt;br /&gt;Note that in the above code you can use double quotaition marks, single quotaition marks, or NO quotaition marks when printing an array's value.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;7&lt;br/&gt;8&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$labels &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;range&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;5&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;10&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;for(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$i &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;5&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$i &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;&lt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;10&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$i&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;++)&lt;br /&gt;   {&lt;br /&gt;   &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$labels&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[] = &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$i&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;   }&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;print_r&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$labels&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt; &lt;br /&gt;&lt;br /&gt;Make all the array &lt;span style="font-weight: bold;"&gt;$labels&lt;/span&gt; contain all of the values between '5' and '10'.&lt;br /&gt;Then add all of the values of &lt;span style="font-weight: bold;"&gt;$i&lt;/span&gt; to the array, &lt;br /&gt;starting at '5' and ending when &lt;span style="font-weight: bold;"&gt;$i&lt;/span&gt; is equal to '10'.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;7&lt;br/&gt;8&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php &lt;br /&gt;$labels &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;range&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;6&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;for(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$i &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$i &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;&lt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;5&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$i&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;++)&lt;br /&gt;   {&lt;br /&gt;   &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$labels&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[] = &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$i&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;   }&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;print_r&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$labels&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;  &lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4889431653894848295-7266336364665054836?l=domyat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://domyat.blogspot.com/feeds/7266336364665054836/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4889431653894848295&amp;postID=7266336364665054836' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4889431653894848295/posts/default/7266336364665054836'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4889431653894848295/posts/default/7266336364665054836'/><link rel='alternate' type='text/html' href='http://domyat.blogspot.com/2008/03/lesson-14-arrays.html' title='Lesson 14 - Arrays'/><author><name>elawael</name><uri>http://www.blogger.com/profile/11684828293686686914</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4889431653894848295.post-2374866715008642247</id><published>2008-03-31T08:28:00.001-07:00</published><updated>2008-03-31T08:30:45.698-07:00</updated><title type='text'>Lesson 13 - Intro to Arrays</title><content type='html'>Now it's time to study one of the most important parts of PHP - arrays. Every programming language in the world has them. Without them you would have millions and millions of loose variables in large scripts.&lt;br /&gt;&lt;br /&gt;Think of arrays as boxes that hold a lot of different variables. For example, think of your cupboard as an array containing all kinds of different foods. Instead of just having them all over the house the cupboard provides a place to put all of these different food so you can easily find them.&lt;br /&gt;&lt;br /&gt;That is like an array - instead of making 20 variables for every user account on your web site you could just make an array that would hold all 20 variables for each member. For example:&lt;br /&gt;&lt;br /&gt;PHP-Code:&lt;br /&gt;&lt;?php&lt;br /&gt;&lt;br /&gt;//storing member values in variables:  &lt;br /&gt;$user_one_age = "20";&lt;br /&gt;$user_one_name = "Bob";&lt;br /&gt;$user_one_url = "learnphpfree.com";&lt;br /&gt;$user_one_phone = "909-555-5555";&lt;br /&gt;$user_one_email = "junk@aol.com";&lt;br /&gt;&lt;br /&gt;//storing member values in an Array:  &lt;br /&gt;$member1 = array('20', 'Bob', 'learnphpfree.com', '909-555-5555', 'junk@aol.com');&lt;br /&gt;&lt;br /&gt;?&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;I'm sure you can see the time/space saving advantage right now Smile. Then if you wanted any of these values you could print them out like this:&lt;br /&gt;PHP-Code:&lt;br /&gt;&lt;?php&lt;br /&gt;&lt;br /&gt;echo $member1[0];&lt;br /&gt;echo $member1[1];&lt;br /&gt;echo $member1[2];&lt;br /&gt;echo $member1[3];&lt;br /&gt;echo $member1[4];&lt;br /&gt;&lt;br /&gt;?&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;which would print:&lt;br /&gt;Code:&lt;br /&gt;&lt;br /&gt;20&lt;br /&gt;Bob&lt;br /&gt;learnphpfree.com&lt;br /&gt;909-555-5555&lt;br /&gt;junk@aol.com&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Notice that arrays start with zero being the first value.&lt;br /&gt;&lt;br /&gt;However, arrays are much more powerful than this! There are MANY ways to make and use arrays in PHP. You will find as you start exploring other scripts that people usually don't use variables - as arrays are much more efficient. But by that same token, remember that arrays are merely groups of variables.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;One of the more popular forms of making arrays is to define the variable names in the array. By default, PHP gives each new item in the array a number starting at zero and going all the way to "infinity". For example, if you were to make an array of all of the letters in the word "Welcome" it would look like this:&lt;br /&gt;&lt;br /&gt;PHP-Code:&lt;br /&gt;&lt;?php&lt;br /&gt;$array = array(W, e, l, c, o, m, e);&lt;br /&gt;echo $array[0]; //Prints "W"&lt;br /&gt;echo $array[4]; //Prints "o"&lt;br /&gt;echo $array[6]; //Prints "e"&lt;br /&gt;?&gt;&lt;br /&gt;&lt;br /&gt;(Notice that arrays start with zero being the first value.)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;However, rather than trying to remember the different variables numbers in an array you can give the variables names:&lt;br /&gt;&lt;br /&gt;PHP-Code:&lt;br /&gt;&lt;?php&lt;br /&gt;$array = array("name" =&gt; 'Sam', "age" =&gt; '20', "url" =&gt; 'learnphpfree.com');&lt;br /&gt;echo $array[name];      //Prints "Sam"&lt;br /&gt;echo $array[age];       //Prints "20"&lt;br /&gt;echo $array[url];       //Prints "learnphpfree.com"&lt;br /&gt;?&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The array syntax is:&lt;br /&gt;&lt;br /&gt;Code:&lt;br /&gt;&lt;br /&gt;array("the_name_of_the_var" =&gt; "the_value_you_want_it_set_to");&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Giving each item a name helps people to remember how to call the values. An example might be an array containing all 150 products of an online store. Rather than trying to remember which product was number "97" in the array, you could name the product "black_sunglasses" instead:&lt;br /&gt;&lt;br /&gt;PHP-Code:&lt;br /&gt;&lt;?php&lt;br /&gt;$products = array("black_sunglasses" =&gt; "Nice pair of Black Sunglasses";&lt;br /&gt;echo $products['black_sunglasses']; //Prints: "Nice pair of Black Sunglasses"&lt;br /&gt;?&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In the next lesson I will show you several ways to make arrays. In the mean time you can read these articles to help you better understand arrays:&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4889431653894848295-2374866715008642247?l=domyat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://domyat.blogspot.com/feeds/2374866715008642247/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4889431653894848295&amp;postID=2374866715008642247' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4889431653894848295/posts/default/2374866715008642247'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4889431653894848295/posts/default/2374866715008642247'/><link rel='alternate' type='text/html' href='http://domyat.blogspot.com/2008/03/lesson-13-intro-to-arrays.html' title='Lesson 13 - Intro to Arrays'/><author><name>elawael</name><uri>http://www.blogger.com/profile/11684828293686686914</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4889431653894848295.post-5697484472361038427</id><published>2008-03-31T08:28:00.000-07:00</published><updated>2008-03-31T08:30:14.466-07:00</updated><title type='text'>Lesson 12 - Advanced Loops</title><content type='html'>Now that we have had a little more practice with control structures I want to introduce the last ones to you. They are "Do while", "switch", "while", "elseif", and "for". First lets start with "switch".&lt;br /&gt;&lt;br /&gt;Switch/Case loops:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Lets say you wanted to find the city someone was from, with a "for" loop your code might look like this:&lt;br /&gt;&lt;br /&gt;PHP-Code:&lt;br /&gt;&lt;?php&lt;br /&gt;    $city = "Temecula";&lt;br /&gt;    if ($city == "L.A.") {&lt;br /&gt;        echo "You live in L.A.";&lt;br /&gt;    } else {&lt;br /&gt;        if ($city == "Dallas") {&lt;br /&gt;            echo "You live in Dallas";&lt;br /&gt;        } else {&lt;br /&gt;            if ($city == "New York") {&lt;br /&gt;                echo "You live in New York";&lt;br /&gt;            } else {&lt;br /&gt;                if ($city == "Washington") {&lt;br /&gt;                    echo "You live in Washington";&lt;br /&gt;                } else {&lt;br /&gt;                    if ($city == "Phoenix") {&lt;br /&gt;                        echo "You live in Phoenix";&lt;br /&gt;                    } else {&lt;br /&gt;                        echo "You live somewhere else...";&lt;br /&gt;                    }&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;?&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;However, if you were to use a "switch" or "case" loop you could make your code a little more friendlier:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;PHP-Code:&lt;br /&gt;&lt;?php&lt;br /&gt;    $city = "Temecula";&lt;br /&gt;    switch($city) {&lt;br /&gt;        case "L.A.": echo "You live in L.A."; break;&lt;br /&gt;        case "Dallas": echo "You live in Dallas"; break;&lt;br /&gt;        case "New York": echo "You live in New York"; break;&lt;br /&gt;        case "Washington": echo "You live in Washington"; break;&lt;br /&gt;        case "Phoenix": echo "You live in Phoenix"; break;&lt;br /&gt;        default: echo "You live somewhere else...";&lt;br /&gt;    }&lt;br /&gt;?&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;As you can see this saves a little more room than an "if" statement. I want you to notice that there is a "break" after each "case" statement. "Break" tells the computer to "stop the code! break out of it!" This keeps PHP from executing each following case statement. These "break" commands are not required, however, without them the case statement will execute every case statement following the "case" statement that is TRUE.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;For example if the code was:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;PHP-Code:&lt;br /&gt;&lt;?php&lt;br /&gt;    $city = "Temecula";&lt;br /&gt;    switch($city) {&lt;br /&gt;        case "L.A.": echo "You live in L.A.";&lt;br /&gt;        case "Dallas": echo "You live in Dallas"; &lt;br /&gt;        case "Temecula": echo "You live in Temecula"; &lt;br /&gt;        case "Washington": echo "You live in Washington";&lt;br /&gt;        case "Phoenix": echo "You live in Phoenix";&lt;br /&gt;        default: echo "You live somewhere else...";&lt;br /&gt;    }&lt;br /&gt;?&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;You would see this print out:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Code:&lt;br /&gt;&lt;br /&gt;You live in Temecula&lt;br /&gt;You live in Washington&lt;br /&gt;You live in Phoenix&lt;br /&gt;You live somewhere else...&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Now don't get me wrong; this is VERY handy for a lot of things, but in this case we want to "break" out of the switch code so we added "break;". One last thing I want you to remember about switch loops is that you don't put a "case" command before the "default" because there is no case left that is why it is the default.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;For Loops&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;There are three parts to a FOR loop: the variable, the condition, and the action. First you define a variable for the loop, then you check that variable against the condition to see if it is TRUE, and last you set an action to happen to the variable at the end of each iteration through the loop. For example:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;PHP-Code:&lt;br /&gt;&lt;?php&lt;br /&gt;    for ($x = 0; $x &lt; 10; $x = $x + 1) {&lt;br /&gt;        echo "$x";&lt;br /&gt;    }&lt;br /&gt;?&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;This loop will print the value of "$x" while "$x" is less than 10. Then it will ad '1' to the value of "$x" and start over.&lt;br /&gt;&lt;br /&gt;Code:&lt;br /&gt;&lt;br /&gt;0&lt;br /&gt;1&lt;br /&gt;2&lt;br /&gt;3&lt;br /&gt;4&lt;br /&gt;5&lt;br /&gt;6&lt;br /&gt;7&lt;br /&gt;8&lt;br /&gt;9&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Now look at this loop:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;PHP-Code:&lt;br /&gt;&lt;?php&lt;br /&gt;$text = "Learn PHP";&lt;br /&gt;&lt;br /&gt;    for ($var = strlen($text); $var &gt; 1; $var = $var - 1) {&lt;br /&gt;        echo "The value of \$var is $var";&lt;br /&gt;    }&lt;br /&gt;?&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;First we made a string called "$text" and put the words "Learn PHP" in it. Remember that the first thing you have to do for a "FOR" loop is make a variable that will control the loop, so I made a variable called "$var" and set it equal to the number of characters in the string "$text" (which is nine). Then I said that while the value of "$var" is greater than "1" ($var &gt; 1) subtract "1" from it ($var - 1). This code will output:&lt;br /&gt;&lt;br /&gt;Code:&lt;br /&gt;&lt;br /&gt;The value of $var is 9&lt;br /&gt;The value of $var is 8&lt;br /&gt;The value of $var is 7&lt;br /&gt;The value of $var is 6&lt;br /&gt;The value of $var is 5&lt;br /&gt;The value of $var is 4&lt;br /&gt;The value of $var is 3&lt;br /&gt;The value of $var is 2&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The code will run the last line (The value of $var is 2) and then subtract "1" from the value of "$var" - at which point the loop will start over again. However, this time the value of "$var" will now be "1" which is NOT greater than "1" so the loop will terminate.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;While&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;A "while" loop is very simple.&lt;br /&gt;&lt;br /&gt;PHP-Code:&lt;br /&gt;&lt;?php&lt;br /&gt;    while ($n == TRUE) {&lt;br /&gt;        do this or that...&lt;br /&gt;    }&lt;br /&gt;?&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In human language it can be read as&lt;br /&gt;&lt;br /&gt;Code:&lt;br /&gt;&lt;br /&gt;"while (the condition) is TRUE do this"&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;For example:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;PHP-Code:&lt;br /&gt;&lt;?php&lt;br /&gt;    $n = TRUE;&lt;br /&gt;    while ($n == TRUE) {&lt;br /&gt;        echo "$n is TRUE!";&lt;br /&gt;    }&lt;br /&gt;?&gt;&lt;br /&gt;&lt;br /&gt;This loop will run forever because it will always equal TRUE. It will just keep printing out "TRUE is TRUE!"&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;You can change the condition to anything you want. Just look at these:&lt;br /&gt;&lt;br /&gt;PHP-Code:&lt;br /&gt;&lt;?php&lt;br /&gt;&lt;br /&gt;    $n = 12;&lt;br /&gt;    while ($n &lt;= 13) {&lt;br /&gt;        echo "$n is less than or equal to 13!";&lt;br /&gt;        $n = $n + 1;&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    $n = 15;&lt;br /&gt;    while ($n &gt; 13) {&lt;br /&gt;        echo "$n is greater than thirteen!";&lt;br /&gt;        $n = $n - 1;&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    $n = 1;&lt;br /&gt;    while ($n != 9) {&lt;br /&gt;        echo "$n is NOT equal to 9!";&lt;br /&gt;        $n++;&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;?&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;if you ran these you would see the following:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Code:&lt;br /&gt;&lt;br /&gt;12 is less than or equal to 13!&lt;br /&gt;13 is less than or equal to 13!&lt;br /&gt;15 is greater than thirteen!&lt;br /&gt;14 is greater than thirteen!&lt;br /&gt;1 is NOT equal to 9!&lt;br /&gt;2 is NOT equal to 9!&lt;br /&gt;3 is NOT equal to 9!&lt;br /&gt;4 is NOT equal to 9!&lt;br /&gt;5 is NOT equal to 9!&lt;br /&gt;6 is NOT equal to 9!&lt;br /&gt;7 is NOT equal to 9!&lt;br /&gt;8 is NOT equal to 9!&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The first loop will run twice before it equals FALSE. In human language it says:&lt;br /&gt;Code:&lt;br /&gt;&lt;br /&gt;make a vaiable named "n" and set it equal to 12&lt;br /&gt;while "$n" is less than or equal to 13&lt;br /&gt;print "(the value of $n) is less than or equal to 13!"&lt;br /&gt;then add "1" to the value of "$n" and start the loop over.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The second while loop will also run twice before it equals FALSE. In human language it says:&lt;br /&gt;Code:&lt;br /&gt;&lt;br /&gt;make a vaiable named "n" and set it equal to 15&lt;br /&gt;while "$n" is greater than 13&lt;br /&gt;print "(the value of $n) is greater than thirteen!"&lt;br /&gt;then subtract "1" from the value of "$n" and start the loop over.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The final while loop will run eight times before it equals FALSE. In human language it says:&lt;br /&gt;Code:&lt;br /&gt;&lt;br /&gt;Set the vaiable named "n" to a value of "1"&lt;br /&gt;while "$n" is NOT greater than nine&lt;br /&gt;print "(the value of $n) is NOT equal to 9!"&lt;br /&gt;then add "1" to the value of "$n" and start the loop over.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Do / While&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;"Do while" loops are like while loops in every way but one - the condition isn't checked to see if it is TRUE until the END of the loop iteration. The following code will run one time before it is checked and found to be FALSE.&lt;br /&gt;&lt;br /&gt;PHP-Code:&lt;br /&gt;&lt;?php&lt;br /&gt;    $number = 8;&lt;br /&gt;    do {&lt;br /&gt;        echo "value of \$number is $number";&lt;br /&gt;    } while ($number &gt; 10);&lt;br /&gt;?&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;this will print:&lt;br /&gt;&lt;br /&gt;Code:&lt;br /&gt;&lt;br /&gt;value of $number is 8&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Lets make some advanced loops and put what we have learned to work.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;For more practice with LOOPS you can visit these sites:&lt;br /&gt;Melonfire&lt;br /&gt;Tizag&lt;br /&gt;pixelDepth switch&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4889431653894848295-5697484472361038427?l=domyat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://domyat.blogspot.com/feeds/5697484472361038427/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4889431653894848295&amp;postID=5697484472361038427' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4889431653894848295/posts/default/5697484472361038427'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4889431653894848295/posts/default/5697484472361038427'/><link rel='alternate' type='text/html' href='http://domyat.blogspot.com/2008/03/lesson-12-advanced-loops.html' title='Lesson 12 - Advanced Loops'/><author><name>elawael</name><uri>http://www.blogger.com/profile/11684828293686686914</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4889431653894848295.post-6640095182756447348</id><published>2008-03-31T08:25:00.000-07:00</published><updated>2008-03-31T08:27:46.701-07:00</updated><title type='text'>Lesson 11 - Adv. Strings</title><content type='html'>&lt;span class="postbody"&gt;Now I want to use these pieces we have discussed to make a couple of interactive scripts. We are going to make a VERY simple one person chat script. I know what your thinking, What good is that!? But this is just to give you some examples of using strings with Loops (Control Structures) and POST. (Later on we will be making a REAL chat script)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Start your text editor - you &lt;span style="font-style: italic;"&gt;should&lt;/span&gt; have SciTE (The Scintilla Text Editor) by now. If not you can find it in &lt;a href="http://www.learnphpfree.com/downloads" target="_blank" class="postlink"&gt;Downloads&lt;/a&gt;&lt;br /&gt;If not open notepad and type this is into it:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;  	  &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt; 	&lt;/tr&gt; 	&lt;tr&gt; 	  &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;7&lt;br/&gt;8&lt;br/&gt;9&lt;br/&gt;10&lt;br/&gt;11&lt;br/&gt;12&lt;br/&gt;13&lt;br/&gt;14&lt;br/&gt;15&lt;br/&gt;16&lt;br/&gt;17&lt;br/&gt;18&lt;br/&gt;19&lt;br/&gt;20&lt;br/&gt;21&lt;br/&gt;22&lt;br/&gt;23&lt;br/&gt;24&lt;br/&gt;25&lt;br/&gt;26&lt;br/&gt;27&lt;br/&gt;28&lt;br/&gt;29&lt;br/&gt;30&lt;br/&gt;31&lt;br/&gt;32&lt;br/&gt;33&lt;br/&gt;34&lt;br/&gt;35&lt;br/&gt;36&lt;br/&gt;37&lt;br/&gt;38&lt;br/&gt;39&lt;br/&gt;40&lt;br/&gt;41&lt;br/&gt;42&lt;br/&gt;43&lt;br/&gt;44&lt;br/&gt;45&lt;br/&gt;46&lt;br/&gt;47&lt;br/&gt;48&lt;br/&gt;49&lt;br/&gt;50&lt;br/&gt;51&lt;br/&gt;52&lt;br/&gt;53&lt;br/&gt;54&lt;br/&gt;55&lt;br/&gt;56&lt;br/&gt;57&lt;br/&gt;58&lt;br/&gt;59&lt;br/&gt;60&lt;br/&gt;61&lt;br/&gt;62&lt;br/&gt;63&lt;br/&gt;64&lt;br/&gt;65&lt;br/&gt;66&lt;br/&gt;67&lt;br/&gt;68&lt;br/&gt;69&lt;br/&gt;70&lt;br/&gt;71&lt;br/&gt;72&lt;br/&gt;&lt;/td&gt; --&gt; 	  &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;/*  &lt;br /&gt;    First we need to define the page's layout &lt;br /&gt;and store it in a string so &lt;br /&gt;    that we can keep our code neat and pretty.&lt;br /&gt;*/    &lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$startofpage &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;html&gt;&lt;body&gt;&lt;table border="\"&gt;&lt;tr&gt;&lt;td&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$endofpage &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/body&gt;&lt;html&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt; &lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Now that we have a basic layout we can move onto writing the code. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/*  Second we need to make a statement that checks to see if&lt;br /&gt;    this is the first time the person has come to this page - &lt;br /&gt;    or in this case has "Posted" anything to this page. This&lt;br /&gt;    will evaluate to FALSE the first time the page is run &lt;br /&gt;    because there will be nothing "Posted" to the page. However,&lt;br /&gt;    after something has BEEN posted from then on this will be TRUE.&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;if (isset(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'text'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;])) {&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$newtext &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'text'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;];&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$oldtext &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'oldtext'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;];&lt;br /&gt;    &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$form2 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;form action="\" method="\"&gt;&lt;br /&gt;        &lt;textarea name="\" rows="\" cols="\"&gt;&lt;br /&gt;        $oldtext  $newtext&lt;/textarea&gt;&lt;br /&gt;        &lt;textarea name="\" rows="\" cols="\"&gt;&lt;/textarea&gt;&lt;br /&gt;        &lt;input name="\" type="\" value="\"&gt;&lt;br /&gt;        &lt;/form&gt;(This is the code run from the \"If\" statement)"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    &lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$startofpage&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$form2&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$endofpage&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    &lt;br /&gt;    &lt;br /&gt;    &lt;br /&gt;    &lt;br /&gt;    &lt;br /&gt;&lt;br /&gt;    &lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;/*  &lt;br /&gt;    Last, if nothing has been posted to the page, (In other words this is the&lt;br /&gt;    first visit) this "else" will be TRUE and the following code will run. &lt;br /&gt;    However, after someone posts something it will be FALSE and the code &lt;br /&gt;    ABOVE will run.&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;    &lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;} else { &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//nothing was posted&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$firstform &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;form action="\" method="\"&gt;&lt;br /&gt;        &lt;textarea name="\" rows="\" cols="\"&gt;&lt;br /&gt;        What is your name?&lt;/textarea&gt;&lt;br /&gt;        &lt;textarea name="\" rows="\" cols="\"&gt;&lt;/textarea&gt;&lt;br /&gt;        &lt;input name="\" type="\" value="\"&gt;&lt;br /&gt;        &lt;/form&gt; (This is the code run from the \"else\" statement)"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;        &lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$startofpage&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$firstform&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$endofpage&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt; 	&lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Ok, now save it as "post.php" (or whatever you want) and upload it to your server and run it. You will see a square border around a large box, a small box, and a "submit" button. When you type something into the second box and press "submit" what you entered will be posted to the first box along with what was already there. After posting a couple of things and giving yourself a pat on the back for a job well done, come back and lets go over the code.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;First lets look at the starting strings:&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;  	  &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt; 	&lt;/tr&gt; 	&lt;tr&gt; 	  &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;&lt;/td&gt; --&gt; 	  &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$startofpage &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;html&gt;&lt;body&gt;&lt;br /&gt;&lt;table border="\"&gt;&lt;tr&gt;&lt;td&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$endofpage &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/body&gt;&lt;html&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt; 	&lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt; &lt;br /&gt;&lt;br /&gt;If you know HTML, (Which you should, if not read the chapters on HTML Before any more PHP lessons) this is just a simple layout. We make a table with one column and one row and center it in the page.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Next we make the first and ONLY Control Structure - an "if" loop:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;  	  &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt; 	&lt;/tr&gt; 	&lt;tr&gt; 	  &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;7&lt;br/&gt;8&lt;br/&gt;9&lt;br/&gt;10&lt;br/&gt;11&lt;br/&gt;12&lt;br/&gt;13&lt;br/&gt;14&lt;br/&gt;15&lt;br/&gt;16&lt;br/&gt;17&lt;br/&gt;&lt;/td&gt; --&gt; 	  &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;if (isset(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'text'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;])) {&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$newtext &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'text'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;];&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$oldtext &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'oldtext'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;];&lt;br /&gt;    &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$form2 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;form action="\" method="\"&gt;&lt;br /&gt;        &lt;textarea name="\" rows="\" cols="\"&gt;&lt;br /&gt;        $oldtext  $newtext&lt;/textarea&gt;&lt;br /&gt;        &lt;textarea name="\" rows="\" cols="\"&gt;&lt;/textarea&gt;&lt;br /&gt;        &lt;input name="\" type="\" value="\"&gt;&lt;br /&gt;        &lt;/form&gt;(This is the code run from the \"If\" statement)"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    &lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$startofpage&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$form2&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$endofpage&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt; 	&lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt; &lt;br /&gt;&lt;br /&gt;This first loop checks to see &lt;span style="font-style: italic;"&gt;if&lt;/span&gt; something was posted to that page: &lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;  	  &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt; 	&lt;/tr&gt; 	&lt;tr&gt; 	  &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;&lt;/td&gt; --&gt; 	  &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;if (isset(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'text'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;])) &lt;br /&gt;[/&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;code&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;In human language that would be&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;:&lt;br /&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;code&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]&lt;br /&gt;if &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;a value in the variable &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"text" &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;has been set&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;/&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;made&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt; 	&lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;If something was posted/set/made/whatever we pull it out an put it in a variable:&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;  	  &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt; 	&lt;/tr&gt; 	&lt;tr&gt; 	  &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;&lt;/td&gt; --&gt; 	  &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$newtext &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'text'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;];&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$oldtext &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'oldtext'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt; 	&lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;(note: we also get the value from "oldtext")&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Then we take those values and put them in a form and show it to the user again:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;  	  &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt; 	&lt;/tr&gt; 	&lt;tr&gt; 	  &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;7&lt;br/&gt;8&lt;br/&gt;9&lt;br/&gt;10&lt;br/&gt;&lt;/td&gt; --&gt; 	  &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$form2 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;form action="\" method="\"&gt;&lt;br /&gt;        &lt;textarea name="\" rows="\" cols="\"&gt;&lt;br /&gt;        $oldtext  $newtext&lt;/textarea&gt;&lt;br /&gt;        &lt;textarea name="\" rows="\" cols="\"&gt;&lt;/textarea&gt;&lt;br /&gt;        &lt;input name="\" type="\" value="\"&gt;&lt;br /&gt;        &lt;/form&gt;(This is the code run from the \"If\" statement)"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    &lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$startofpage&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$form2&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$endofpage&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt; 	&lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;That would end the code that would run. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;However, if nothing was posted to the page, i.e. this is the first visit, the "if" would be FALSE and PHP would move on to the "else" statement:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;  	  &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt; 	&lt;/tr&gt; 	&lt;tr&gt; 	  &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;7&lt;br/&gt;8&lt;br/&gt;9&lt;br/&gt;10&lt;br/&gt;11&lt;br/&gt;12&lt;br/&gt;13&lt;br/&gt;14&lt;br/&gt;15&lt;br/&gt;16&lt;br/&gt;17&lt;br/&gt;&lt;/td&gt; --&gt; 	  &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;} else { &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//nothing was posted&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$firstform &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;form action="\" method="\"&gt;&lt;br /&gt;        &lt;textarea name="\" rows="\" cols="\"&gt;&lt;br /&gt;        What is your name?&lt;/textarea&gt;&lt;br /&gt;        &lt;textarea name="\" rows="\" cols="\"&gt;&lt;/textarea&gt;&lt;br /&gt;        &lt;input name="\" type="\" value="\"&gt;&lt;br /&gt;        &lt;/form&gt; (This is the code run from the \"else\" statement)"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;        &lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$startofpage&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$firstform&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$endofpage&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt; 	&lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;First we would make a form and put the starting text in "oldtext". Then we would make a field called "text" where the user would answer. So now we have TWO values in this form "oldtext" and "text"&lt;br /&gt;(note: this is the same as the other form)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Then all we need to do is print the form to the user and we are done:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;  	  &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt; 	&lt;/tr&gt; 	&lt;tr&gt; 	  &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;&lt;/td&gt; --&gt; 	  &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$startofpage&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$firstform&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$endofpage&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt; 	&lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Note: I put code below each form so that when you are experimenting with this script you will know which loop has run - "if" or "else".&lt;br /&gt;&lt;br /&gt;Note: If you leave the page and come back, what you have entered will be lost because this script is not saving what you post anywhere. It is just passing the value and the old value back to the page every time it is run.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;So the COMPLETE CODE is this:&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;  	  &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt; 	&lt;/tr&gt; 	&lt;tr&gt; 	  &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;7&lt;br/&gt;8&lt;br/&gt;9&lt;br/&gt;10&lt;br/&gt;11&lt;br/&gt;12&lt;br/&gt;13&lt;br/&gt;14&lt;br/&gt;15&lt;br/&gt;16&lt;br/&gt;17&lt;br/&gt;18&lt;br/&gt;19&lt;br/&gt;20&lt;br/&gt;21&lt;br/&gt;22&lt;br/&gt;23&lt;br/&gt;24&lt;br/&gt;25&lt;br/&gt;26&lt;br/&gt;27&lt;br/&gt;28&lt;br/&gt;29&lt;br/&gt;30&lt;br/&gt;31&lt;br/&gt;32&lt;br/&gt;33&lt;br/&gt;34&lt;br/&gt;35&lt;br/&gt;&lt;/td&gt; --&gt; 	  &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;br /&gt;$startofpage &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;html&gt;&lt;body&gt;&lt;table border="\"&gt;&lt;tr&gt;&lt;td&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$endofpage &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/body&gt;&lt;html&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;if (isset(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'text'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;])) {&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$newtext &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'text'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;];&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$oldtext &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'oldtext'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;];&lt;br /&gt;    &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$form2 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;form action="\" method="\"&gt;&lt;br /&gt;        &lt;textarea name="\" rows="\" cols="\"&gt;&lt;br /&gt;        $oldtext  $newtext&lt;/textarea&gt;&lt;br /&gt;        &lt;textarea name="\" rows="\" cols="\"&gt;&lt;/textarea&gt;&lt;br /&gt;        &lt;input name="\" type="\" value="\"&gt;&lt;br /&gt;        &lt;/form&gt;(This is the code run from the \"If\" statement)"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    &lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$startofpage&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$form2&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$endofpage&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;    &lt;br /&gt;} else { &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//nothing was posted&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$firstform &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;form action="\" method="\"&gt;&lt;br /&gt;        &lt;textarea name="\" rows="\" cols="\"&gt;&lt;br /&gt;        What is your name?&lt;/textarea&gt;&lt;br /&gt;        &lt;textarea name="\" rows="\" cols="\"&gt;&lt;/textarea&gt;&lt;br /&gt;        &lt;input name="\" type="\" value="\"&gt;&lt;br /&gt;        &lt;/form&gt; (This is the code run from the \"else\" statement)"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;        &lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$startofpage&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$firstform&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$endofpage&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt; 	&lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt; &lt;br /&gt;&lt;br /&gt;Note: You can download this file below.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Now that we have a functional script lets do something?s to it! First up, did you notice that every time you post something that the "What is your Name?" text moves over more? This is because there is space between the &lt;textarea&gt; and the "what is your name?" text. and every time you repost the "oldtext" variable you take that space and re-add it to it.&lt;br /&gt;&lt;br /&gt;If you aren't following me sorry, I'm not that good at explaining... Anyway, lets fix it!&lt;br /&gt;&lt;br /&gt;This is a handy function called "trim" which strips whitespace (or other characters) from the beginning and end of a string. so lets add this to the script:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;  	  &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt; 	&lt;/tr&gt; 	&lt;tr&gt; 	  &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;7&lt;br/&gt;8&lt;br/&gt;9&lt;br/&gt;10&lt;br/&gt;11&lt;br/&gt;12&lt;br/&gt;13&lt;br/&gt;14&lt;br/&gt;15&lt;br/&gt;16&lt;br/&gt;&lt;/td&gt; --&gt; 	  &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;if (isset(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'text'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;])) {&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$newtext &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'text'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;];&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$oldtext &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'oldtext'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;];&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$newtext &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;trim&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$newtext&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);     &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//Added!&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$oldtext &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;trim&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$oldtext&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);     &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//Added!&lt;br /&gt;    &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$form2 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;form action="\" method="\"&gt;&lt;br /&gt;        &lt;textarea name="\" rows="\" cols="\"&gt;&lt;br /&gt;        $oldtext  $newtext&lt;/textarea&gt;&lt;br /&gt;        &lt;textarea name="\" rows="\" cols="\"&gt;&lt;/textarea&gt;&lt;br /&gt;        &lt;input name="\" type="\" value="\"&gt;&lt;br /&gt;        &lt;/form&gt;(This is the code run from the \"If\" statement)"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    &lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$startofpage&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$form2&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$endofpage&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt; 	&lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;This will keep the code clean!&lt;br /&gt;&lt;br /&gt;Now lets suppose that someone is really bored (and boring) and rather than doing something for this world, they waste their time by trying to take down web sites for no reason. So with this form someone could post some kind of malicious code that might redirect to another site (I am sure you can figure out where) or mess-up our layout or something. So now we are going to add another string function to our code that searches the string for any dangerous PHP or HTML characters and removes them.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;  	  &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt; 	&lt;/tr&gt; 	&lt;tr&gt; 	  &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;7&lt;br/&gt;8&lt;br/&gt;9&lt;br/&gt;10&lt;br/&gt;11&lt;br/&gt;12&lt;br/&gt;13&lt;br/&gt;14&lt;br/&gt;15&lt;br/&gt;16&lt;br/&gt;&lt;/td&gt; --&gt; 	  &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;if (isset(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'text'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;])) {&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$newtext &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'text'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;];&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$oldtext &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'oldtext'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;];&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$newtext &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;strip_tags&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;trim&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$newtext&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;));     &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//Added Again!&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$oldtext &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;strip_tags&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;trim&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$oldtext&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;));     &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//Added Again!&lt;br /&gt;    &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$form2 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;form action="\" method="\"&gt;&lt;br /&gt;        &lt;textarea name="\" rows="\" cols="\"&gt;&lt;br /&gt;        $oldtext  $newtext&lt;/textarea&gt;&lt;br /&gt;        &lt;textarea name="\" rows="\" cols="\"&gt;&lt;/textarea&gt;&lt;br /&gt;        &lt;input name="\" type="\" value="\"&gt;&lt;br /&gt;        &lt;/form&gt;(This is the code run from the \"If\" statement)"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    &lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$startofpage&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$form2&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$endofpage&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt; 	&lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;Now we trim the code down to the text by removing extra spaces and such with "trim" and then remove any PHP or HTML code that might mess up the page with "strip_tags". What is left is then put in to the variable.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Extra Addons to the code&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Now lets add some code that prints how many words were posted back to the user. For this we are going to use the "str_word_count" function. We can also add "strlen" to print out how many characters are in the posted comment.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;  	  &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt; 	&lt;/tr&gt; 	&lt;tr&gt; 	  &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;7&lt;br/&gt;8&lt;br/&gt;9&lt;br/&gt;10&lt;br/&gt;11&lt;br/&gt;12&lt;br/&gt;13&lt;br/&gt;14&lt;br/&gt;15&lt;br/&gt;16&lt;br/&gt;17&lt;br/&gt;18&lt;br/&gt;19&lt;br/&gt;20&lt;br/&gt;21&lt;br/&gt;22&lt;br/&gt;23&lt;br/&gt;&lt;/td&gt; --&gt; 	  &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;if (isset(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'text'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;])) {&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$newtext &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'text'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;];&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$oldtext &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'oldtext'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;];&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$newtext &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;strip_tags&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;trim&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$newtext&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;));     &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$oldtext &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;strip_tags&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;trim&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$oldtext&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;));&lt;br /&gt;    &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$form2 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;form action="\" method="\"&gt;&lt;br /&gt;        &lt;textarea name="\" rows="\" cols="\"&gt;&lt;br /&gt;        $oldtext  $newtext&lt;/textarea&gt;&lt;br /&gt;        &lt;textarea name="\" rows="\" cols="\"&gt;&lt;/textarea&gt;&lt;br /&gt;        &lt;input name="\" type="\" value="\"&gt;&lt;br /&gt;        &lt;/form&gt;(This is the code run from the \"If\" statement)"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    &lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$startofpage&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$form2&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Just Added&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"You Posted "&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;str_word_count&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$newtext&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;" words and "&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;strlen&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$newtext&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Characters."&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Just Added   &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$endofpage&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt; 	&lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;Here we passed the variable "$newtext" that holds what the user posted to the function str_word_count which then returned the number of word in the variable.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Now we are going to add a function called "ord" that echo?s the first characters ASCII value. This only serves as an example of more things you can to your strings.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;  	  &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt; 	&lt;/tr&gt; 	&lt;tr&gt; 	  &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;7&lt;br/&gt;8&lt;br/&gt;9&lt;br/&gt;10&lt;br/&gt;11&lt;br/&gt;12&lt;br/&gt;13&lt;br/&gt;14&lt;br/&gt;15&lt;br/&gt;16&lt;br/&gt;17&lt;br/&gt;18&lt;br/&gt;19&lt;br/&gt;20&lt;br/&gt;21&lt;br/&gt;22&lt;br/&gt;23&lt;br/&gt;24&lt;br/&gt;25&lt;br/&gt;26&lt;br/&gt;27&lt;br/&gt;28&lt;br/&gt;29&lt;br/&gt;&lt;/td&gt; --&gt; 	  &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;if (isset(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'text'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;])) {&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$newtext &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'text'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;];&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$oldtext &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'oldtext'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;];&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$newtext &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;strip_tags&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;trim&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$newtext&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;));     &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$oldtext &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;strip_tags&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;trim&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$oldtext&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;));&lt;br /&gt;    &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$form2 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;form action="\" method="\"&gt;&lt;br /&gt;        &lt;textarea name="\" rows="\" cols="\"&gt;&lt;br /&gt;        $oldtext  $newtext&lt;/textarea&gt;&lt;br /&gt;        &lt;textarea name="\" rows="\" cols="\"&gt;&lt;/textarea&gt;&lt;br /&gt;        &lt;input name="\" type="\" value="\"&gt;&lt;br /&gt;        &lt;/form&gt;(This is the code run from the \"If\" statement)"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    &lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$startofpage&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$form2&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;""&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//Added to center the text&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"You Posted "&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;str_word_count&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$newtext&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;" words and "&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;strlen&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$newtext&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Characters."&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;  &lt;br /&gt;    &lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Here is the ASCII Value for the first character you posted: "&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;  &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//Added&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;ord&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$newtext&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);  &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//Added&lt;br /&gt;    &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;""&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//Added to center the text&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$endofpage&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt; 	&lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;This Fun addon will print the users post backwards!&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;  	  &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt; 	&lt;/tr&gt; 	&lt;tr&gt; 	  &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;7&lt;br/&gt;8&lt;br/&gt;9&lt;br/&gt;10&lt;br/&gt;11&lt;br/&gt;12&lt;br/&gt;13&lt;br/&gt;14&lt;br/&gt;15&lt;br/&gt;16&lt;br/&gt;17&lt;br/&gt;18&lt;br/&gt;19&lt;br/&gt;&lt;/td&gt; --&gt; 	  &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$startofpage&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$form2&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;""&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"You Posted "&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;str_word_count&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$newtext&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;" words and "&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;strlen&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$newtext&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Characters."&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;  &lt;br /&gt;    &lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Here is the ASCII Value for the first character you posted: "&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;ord&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$newtext&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;    &lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Here is your text Backwards: "&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//Added&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;strrev&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$newtext&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);  &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//Added&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;""&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$endofpage&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt; 	&lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;You can also build a bad-word filter to keep your posts clean! For that we can use the function "str_replace" which works like this:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;  	  &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt; 	&lt;/tr&gt; 	&lt;tr&gt; 	  &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;&lt;/td&gt; --&gt; 	  &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;br /&gt;$bodytag &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;str_replace&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"%body%"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"black"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;body text="'%body%'"&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Provides: &lt;body text="'black'"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt; 	&lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;  	  &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt; 	&lt;/tr&gt; 	&lt;tr&gt; 	  &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;&lt;/td&gt; --&gt; 	  &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;if (isset(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'text'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;])) {&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$newtext &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;strip_tags&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;trim&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'text'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]));&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$oldtext &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;strip_tags&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;trim&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'oldtext'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]));&lt;br /&gt;    &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$badwords &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= array(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"sucks"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"damn"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"#!@?"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"ASP"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);  &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//Added&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$newtext &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;str_replace&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$badwords&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"****"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"$newtext"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);  &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//Added &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt; 	&lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;You can add more words to the filter, just put a "," after each one.&lt;br /&gt;&lt;br /&gt;Ok, well that is it for this script, but don't worry we will make a real chat script soon enough. However this was good practice using strings and posts.&lt;br /&gt;&lt;br /&gt;If you want to do more with this script you can visit &lt;a href="http://us2.php.net/strings" target="_blank" class="postlink"&gt;PHP.net - Strings&lt;/a&gt; for more functions and examples of how to use them.&lt;br /&gt;&lt;br /&gt;You can also download the complete "post.php" file below. I incourage you to try to add more things to this script maybe something that makes all of the text entered &lt;a href="http://us2.php.net/manual/en/function.strtolower.php" target="_blank" class="postlink"&gt;LOWER CASE&lt;/a&gt;.&lt;br /&gt;You can &lt;a href="http://beta.learnphpfree.com/lessonfiles/LPF_lesson_11.zip" target="_blank" class="postlink"&gt;download the file here&lt;/a&gt;.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4889431653894848295-6640095182756447348?l=domyat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://domyat.blogspot.com/feeds/6640095182756447348/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4889431653894848295&amp;postID=6640095182756447348' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4889431653894848295/posts/default/6640095182756447348'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4889431653894848295/posts/default/6640095182756447348'/><link rel='alternate' type='text/html' href='http://domyat.blogspot.com/2008/03/lesson-11-adv-strings.html' title='Lesson 11 - Adv. Strings'/><author><name>elawael</name><uri>http://www.blogger.com/profile/11684828293686686914</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4889431653894848295.post-910099479370652573</id><published>2008-03-31T08:22:00.000-07:00</published><updated>2008-03-31T08:24:40.896-07:00</updated><title type='text'>Lesson 10 - Review</title><content type='html'>&lt;span class="postbody"&gt;I would like to use this lesson to go back over what we have learned about variables, strings, and control structures. If you feel you have mastered these then you are welcome to skip this lesson.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;So once again, a variable can be given any of the following values, any of the following ways:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;7&lt;br/&gt;8&lt;br/&gt;9&lt;br/&gt;10&lt;br/&gt;11&lt;br/&gt;12&lt;br/&gt;13&lt;br/&gt;14&lt;br/&gt;15&lt;br/&gt;16&lt;br/&gt;17&lt;br/&gt;18&lt;br/&gt;19&lt;br/&gt;20&lt;br/&gt;21&lt;br/&gt;22&lt;br/&gt;23&lt;br/&gt;24&lt;br/&gt;25&lt;br/&gt;26&lt;br/&gt;27&lt;br/&gt;28&lt;br/&gt;29&lt;br/&gt;30&lt;br/&gt;31&lt;br/&gt;32&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//Numbers:&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$var1 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"993"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;  &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//$var1 is equal to 993&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$var2 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;993&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;    &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//$var2 is equal to 993&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$var3 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'993'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;  &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//$var3 is equal to 993&lt;br /&gt;&lt;br /&gt;//Letters:&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$var4 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"G"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$var5 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'G'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//Characters:&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$var6 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'%'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$var7 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"+"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//Variables:&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$var8 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'8'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$var9 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$var8&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;                  &lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//Variable 9 ($var9) is now equal to "8"&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$var9&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;++;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$var10 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$var9&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;               &lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//Variable 10 is now equal to "9" ("8" plus one, or "++") &lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$var11 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$var10 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;+ &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$var8&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;        &lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//Variable 11 is now equal to 17&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$var12 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= ((&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;0.1&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;+&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;0.7&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) * &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;10&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;); &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// $var12 is equal to 8&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$var13 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'((0.1+0.7) * 10)'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// $var12 is equal to "((0. 1+0.7)*10)"!&lt;br /&gt;//Remember the '' means ABSOLUTE VALUE, while "" means PHP evaluates it. &lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;A variable can hold a letter or any number. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Strings hold long "strings" of letters or numbers - like as a sentence. All of the following are strings:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Sentences:&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;7&lt;br/&gt;8&lt;br/&gt;9&lt;br/&gt;10&lt;br/&gt;11&lt;br/&gt;12&lt;br/&gt;13&lt;br/&gt;14&lt;br/&gt;15&lt;br/&gt;16&lt;br/&gt;17&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$string1 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Welcome to Learnphpfree.com"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$string2 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"5448 Longroad, Somewhere, CA 99999"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$string3 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"I love programming!?"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$string4 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Learn"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$string5 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;" PHP"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$string6 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;" Free!"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$string7 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"$string4 $string5 $string6"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;          &lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//String 7 is "Learn PHP Free!"&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$string8 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"$var8 visitors to Learnphpfree.com"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//String 8 is equal to "8 visitors to Learnphpfree.com"&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$string9 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$var11&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;. &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;" visitors to Learnphpfree.com"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;. &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;' Since yesterday'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//String 9 is equal to "17 visitors to Learnphpfree.com Since yesterday"&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt; &lt;br /&gt;&lt;br /&gt;You will be doing a lot with strings so make sure and practice with them on your own so that you know them well.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Control Structures are the logic of the code. Remember that if the "if" is FALSE than PHP while run the "else" statement, but if the "if" is true PHP will ignore the "else" statement.&lt;br /&gt;&lt;br /&gt;Remember that these characters dictate the control structure:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="90%"&gt;&lt;tbody&gt;&lt;tr&gt;    &lt;td&gt;&lt;span class="genmed"&gt;&lt;b&gt;Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt;   &lt;td id="code"&gt;&lt;br /&gt;"&gt;" means "Greater than"&lt;br /&gt;"&lt;" means "less than"&lt;br /&gt;"==" means "value is equal"&lt;br /&gt;"=" means "make equal"&lt;br /&gt;"&amp;amp;&amp;amp;" means "and"&lt;br /&gt;"||" means "or"&lt;br /&gt;"+" means "plus"&lt;br /&gt;"-" means "minus"&lt;br /&gt;"!" means "NOT"&lt;br /&gt;"!=" means "NOT equal"&lt;br /&gt;"&gt;+" means "Greater than or equal to"&lt;br /&gt;&lt;/td&gt; &lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Here are a couple simple ones:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;7&lt;br/&gt;8&lt;br/&gt;9&lt;br/&gt;10&lt;br/&gt;11&lt;br/&gt;12&lt;br/&gt;13&lt;br/&gt;14&lt;br/&gt;15&lt;br/&gt;16&lt;br/&gt;17&lt;br/&gt;18&lt;br/&gt;19&lt;br/&gt;20&lt;br/&gt;21&lt;br/&gt;22&lt;br/&gt;23&lt;br/&gt;24&lt;br/&gt;25&lt;br/&gt;26&lt;br/&gt;27&lt;br/&gt;28&lt;br/&gt;29&lt;br/&gt;30&lt;br/&gt;31&lt;br/&gt;32&lt;br/&gt;33&lt;br/&gt;34&lt;br/&gt;35&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;if (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) {&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"1 is greater than 0"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;} else {&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"1 is not greater than 0"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//the "if" is TRUE because 1 is greater than 0&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;if (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;== &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) {&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"1 is equal to 0"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;} else {&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"1 is not equal to 0"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//the "if" is FALSE because 1 is NOT equal to 0&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;if (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;!= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) {&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"1 is not equal to 0"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;} else {&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"1 is equal to 0"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//the "if" is TRUE because 1 is NOT equal to 0&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;if (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) {&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"1 is greater than or equal to 0"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;} else {&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"1 is not greater than or equal to 0"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//the "if" is TRUE because 1 is greater or equal to 0&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;ADVANCED LOOPS:&lt;br /&gt;&lt;br /&gt;For "&amp;amp;&amp;amp;" both have to be TRUE for the "if" to be true.&lt;br /&gt;For "||" only one has to be TRUE for the "if" to be true.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;7&lt;br/&gt;8&lt;br/&gt;9&lt;br/&gt;10&lt;br/&gt;11&lt;br/&gt;12&lt;br/&gt;13&lt;br/&gt;14&lt;br/&gt;15&lt;br/&gt;16&lt;br/&gt;17&lt;br/&gt;18&lt;br/&gt;19&lt;br/&gt;20&lt;br/&gt;21&lt;br/&gt;22&lt;br/&gt;23&lt;br/&gt;24&lt;br/&gt;25&lt;br/&gt;26&lt;br/&gt;27&lt;br/&gt;28&lt;br/&gt;29&lt;br/&gt;30&lt;br/&gt;31&lt;br/&gt;32&lt;br/&gt;33&lt;br/&gt;34&lt;br/&gt;35&lt;br/&gt;36&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;if ((&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) &amp;amp;&amp;amp; (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;2 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)) {&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"1 is greater than 0 AND 2 is greater than 0"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;} else {&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"1 is not greater than 0 AND/OR 2 is not greater than 0"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//the "if" is TRUE because BOTH are greater than 0&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;if ((&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) &amp;amp;&amp;amp; (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;2 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)) {&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"1 is greater than 0 AND 2 is greater than 0"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;} else {&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"1 is not greater than 0 AND/OR 2 is not greater than 0"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//the "if" is TRUE because BOTH are greater than 0&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;if ((&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) || (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;2 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;== &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)) {&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"1 is greater than 0 OR 2 is equal to 0"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;} else {&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"1 is not greater than 0 OR 2 is not equal to 0"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//the "if" is TRUE because the first statement is TRUE even though the second is FALSE.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;if ((&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;&lt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) || (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;2 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)) {&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"1 is less than 0 OR 2 is greater than or equal to 0"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;} else {&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"1 is not less than 0 OR 2 is not greater than or equal to 0"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//the "if" is TRUE because the first statement is FALSE but the second is TRUE.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Last I would like YOU to try to make your own "if" statements and try making and messing with strings and variables too! &lt;a href="http://beta.learnphpfree.com/lessonfiles/LPF_lesson_10.zip" target="_blank" class="postlink"&gt;]Here&lt;/a&gt; is a zip archive of the loops, variables, and strings files. Upload them to your own site and experiment changing them. You need to make sure you understand them well.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4889431653894848295-910099479370652573?l=domyat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://domyat.blogspot.com/feeds/910099479370652573/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4889431653894848295&amp;postID=910099479370652573' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4889431653894848295/posts/default/910099479370652573'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4889431653894848295/posts/default/910099479370652573'/><link rel='alternate' type='text/html' href='http://domyat.blogspot.com/2008/03/lesson-10-review.html' title='Lesson 10 - Review'/><author><name>elawael</name><uri>http://www.blogger.com/profile/11684828293686686914</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4889431653894848295.post-7615520898396658230</id><published>2008-03-31T08:19:00.000-07:00</published><updated>2008-03-31T08:21:43.652-07:00</updated><title type='text'>Lesson 9 - Loops and POST</title><content type='html'>&lt;span class="postbody"&gt;&lt;span style="font-weight: bold;"&gt;Using Control Structures and Superglobals together&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Today we are going to make a page that is TOTALY dynamic and will only display something after a condition is met. But first I want to do a small warn-up exercise to get you thinking in loops! lol. Open up your text editor and type the following PHP code into it:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;7&lt;br/&gt;8&lt;br/&gt;9&lt;br/&gt;10&lt;br/&gt;11&lt;br/&gt;12&lt;br/&gt;13&lt;br/&gt;14&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;if (!isset(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'page'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;])) {&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$page_num &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    }&lt;br /&gt;if (isset(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'page'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;])) {&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$page_num &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'page'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;];&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$page_num&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;++;  &lt;br /&gt;    &lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;form method="\"&gt;"&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;.&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;input type="\" name="\" value="\"&gt;"&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;.&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;/form&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Save the file as "simplepost.php", upload it to your web server, and then run it. you will see a button that increases by "1" every time you click it! Now lets go over the PHP code. The first "if" statement tests to see if you have NOT pasted a variable to the PHP file. If "TRUE", you have NOT passed a variable called "page" to the PHP script it will make a variable called "$page_num" and set it equal to "0".&lt;br /&gt;&lt;br /&gt;This second "if" statement checks to see if you HAVE passed a variable to this file. If you have passed the variable "page" to this file - it makes a new variable called "$page_num" and sets it equal to the posted variable "page". ($page_num = $_POST['page']). Remember that because the first if statement is FALSE the variable ($page_num = 0)was NEVER MADE.&lt;br /&gt;&lt;br /&gt;After we get the variable "$page_num", we increase it by "1" ($page_num++) and stick it into our HTML form that posts back to this PHP file!&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Well, that was pretty easy; lets try something a little harder. Such as a file that is a little smarter as to what it outputs and when. Open up your text editor and type the following code into it:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;7&lt;br/&gt;8&lt;br/&gt;9&lt;br/&gt;10&lt;br/&gt;11&lt;br/&gt;12&lt;br/&gt;13&lt;br/&gt;14&lt;br/&gt;15&lt;br/&gt;16&lt;br/&gt;17&lt;br/&gt;18&lt;br/&gt;19&lt;br/&gt;20&lt;br/&gt;21&lt;br/&gt;22&lt;br/&gt;23&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;if (!isset(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'page'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;])) {&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$page_num &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;form method="\"&gt;"&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;.&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;input type="\" name="\" value="\"&gt;"&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;.&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;/form&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;elseif (isset(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'page'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;])) { &lt;br /&gt;    if (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'page'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;] &lt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;5&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) {&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$page_num &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'page'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;];&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$page_num&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;++;&lt;br /&gt;        echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;form method="\"&gt;"&lt;br /&gt;            &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;.&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;input type="\" name="\" value="\"&gt;"&lt;br /&gt;            &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;.&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;/form&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    }&lt;br /&gt;    elseif (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'page'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;] == &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;5&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) {&lt;br /&gt;        echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"You made it to page 5!"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Save it as "postloop.php" (with the quotes) and upload it to your web server and run it. You will see a button that has a number in it that starts at "0" and goes up by one each time you click it until you get to the number "5" at which point you see the message: "You made it to page 5!". Now here is the PHP code with a description of each part:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;    &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;7&lt;br/&gt;8&lt;br/&gt;9&lt;br/&gt;10&lt;br/&gt;11&lt;br/&gt;12&lt;br/&gt;13&lt;br/&gt;14&lt;br/&gt;15&lt;br/&gt;16&lt;br/&gt;17&lt;br/&gt;18&lt;br/&gt;19&lt;br/&gt;20&lt;br/&gt;21&lt;br/&gt;22&lt;br/&gt;23&lt;br/&gt;24&lt;br/&gt;25&lt;br/&gt;26&lt;br/&gt;27&lt;br/&gt;28&lt;br/&gt;29&lt;br/&gt;30&lt;br/&gt;31&lt;br/&gt;32&lt;br/&gt;33&lt;br/&gt;34&lt;br/&gt;35&lt;br/&gt;36&lt;br/&gt;37&lt;br/&gt;38&lt;br/&gt;39&lt;br/&gt;40&lt;br/&gt;41&lt;br/&gt;42&lt;br/&gt;43&lt;br/&gt;&lt;/td&gt; --&gt;    &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;if (!isset(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'page'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;])) { &lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;/* IF there was nothing posted to the page (aka. first visit) do this: */&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$page_num &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//make a variable called $page_num and set it to ZERO &lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;form method="\"&gt;"&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;.&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;input type="\" name="\" value="\"&gt;"&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;.&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;/form&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;/* make a HTML form that "POSTS" the value of "$page_num" to itsself . Notice that the name of the "input" button in the form is "page" and the value is the value of $page_num.&lt;br /&gt;&lt;br /&gt;If you look at the top "if" statment, it says "if $_POST['page'] is NOT set" - that is the same name as the "input" button (name=\"page\"). So next time this file runs it will ignore this "if" statment because it will be FALSE. (Something will be posted named "page")*/&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;elseif (isset(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'page'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;])) { &lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;/* if something named "page" was posted do this: (AKA 2nd to last visit)*/&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;if (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'page'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;] &lt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;5&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) { &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;/* if the valued of "page" is less than five do this: (aka 2nd to 5th visit)*/&lt;br /&gt;    &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$page_num &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'page'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]; &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// put the posted value into a var named $page_num&lt;br /&gt;        &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$page_num&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;++;&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// increase $page_num by one&lt;br /&gt;        &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;form method="\"&gt;"&lt;br /&gt;            &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;.&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;input type="\" name="\" value="\"&gt;"&lt;br /&gt;            &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;.&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;/form&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;/* print the form with the value of $page_num now increased by one */&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;}&lt;br /&gt;    elseif (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'page'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;] == &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;5&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) {&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;/* if the valued of "page" is equal to five do this statement. (This is the last page you see (aka page 6)) */&lt;br /&gt;    &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"You made it to page 5!"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;As over whelming as this PHP code may seem, it really is easier than it looks if you don't let it scare you. There are only four "if/elseif" statements in this code and if you look at each one individually you should have no problem understanding what they do.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4889431653894848295-7615520898396658230?l=domyat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://domyat.blogspot.com/feeds/7615520898396658230/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4889431653894848295&amp;postID=7615520898396658230' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4889431653894848295/posts/default/7615520898396658230'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4889431653894848295/posts/default/7615520898396658230'/><link rel='alternate' type='text/html' href='http://domyat.blogspot.com/2008/03/lesson-9-loops-and-post.html' title='Lesson 9 - Loops and POST'/><author><name>elawael</name><uri>http://www.blogger.com/profile/11684828293686686914</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4889431653894848295.post-8980308754124643643</id><published>2008-03-31T08:18:00.000-07:00</published><updated>2008-03-31T08:19:36.580-07:00</updated><title type='text'>Lesson 8 - Control Structures 2</title><content type='html'>else - elseif - while&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Now that you understand "IF" lets look at some other control structures - "else", "elseif", and "while". (The good thing about PHP is that you can kind of guess what each function or control structure does just by looking at its name).Lets start with "else".&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;"Often you'd want to execute a statement if a certain condition is met, and a different statement if the condition is NOT met. This is what else is for. else extends an if statement to execute a statement in case the expression in the if statement evaluates to FALSE." - php.net.&lt;br /&gt;&lt;br /&gt;Taking our previous "if.php" code we could change it to:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;PHP-Code:&lt;br /&gt;&lt;?php&lt;br /&gt;    If ($your_number &gt; $cpu_number) {&lt;br /&gt;    /* "if" $your_number is greater than $cpu_number do the following: */&lt;br /&gt;    echo "Your Number Is Bigger!";&lt;br /&gt;    } else {&lt;br /&gt;    /* "if" $your_number is less than $cpu_number do the following: */&lt;br /&gt;    echo "Your Number Is Smaller!";&lt;br /&gt;    }&lt;br /&gt;?&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Logic example:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;PHP-Code:&lt;br /&gt;&lt;?php&lt;br /&gt;if (expression = true)&lt;br /&gt;    then do statement&lt;br /&gt;else //"if" FALSE&lt;br /&gt;    then do this statement&lt;br /&gt;?&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;"elseif"&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;"elseif, as its name suggests, is a combination of if and else. Like else, it extends an if statement to execute a different statement in case the original if expression evaluates to FALSE. However, unlike else, it will execute that alternative expression only if the elseif conditional expression evaluates to TRUE." - php.net.&lt;br /&gt;&lt;br /&gt;Taking our previous "if.php" code we could change it to:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;PHP-Code:&lt;br /&gt;&lt;?php&lt;br /&gt;    If ($your_number &gt; $cpu_number) {&lt;br /&gt;    /* "if" $your_number is greater than $cpu_number do the following: */&lt;br /&gt;    echo "Your Number Is Bigger!";&lt;br /&gt;    } elseif ($your_number == $cpu_number) {&lt;br /&gt;    /* "if" $your_number is equal to $cpu_number do the following: */&lt;br /&gt;    echo "Your Number Is Equal to the CPU's!";&lt;br /&gt;    } else {&lt;br /&gt;    /* "if" $your_number is less than $cpu_number do the following: */&lt;br /&gt;    echo "Your Number Is Smaller!";&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;?&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Logic example:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;PHP-Code:&lt;br /&gt;&lt;?php&lt;br /&gt;if (expression = true)&lt;br /&gt;    then do statement&lt;br /&gt;elseif (expression = true)&lt;br /&gt;    then do this statement&lt;br /&gt;else //"if" everything else is FALSE&lt;br /&gt;    then do this statement&lt;br /&gt;?&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;"There may be several elseif's within the same if statement. The first elseif expression (if any) that evaluates to TRUE would be executed. In PHP, you can also write 'else if' (in two words) and the behavior would be identical to the one of 'elseif' (in a single word). The syntactic meaning is slightly different (if you're familiar with C, this is the same behavior) but the bottom line is that both would result in exactly the same behavior.&lt;br /&gt;&lt;br /&gt;The elseif statement is only executed if the preceding if expression and any preceding elseif expressions evaluated to FALSE, and the current elseif expression evaluated to TRUE." - php.net.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;"while"&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;"while loops are the simplest type of loop in PHP. They behave just like their C counterparts.&lt;br /&gt;&lt;br /&gt;The meaning of a while statement is simple. It tells PHP to execute the nested statement(s) repeatedly, as long as the while expression evaluates to TRUE. The value of the expression is checked each time at the beginning of the loop, so even if this value changes during the execution of the nested statement(s), execution will not stop until the end of the iteration (each time PHP runs the statements in the loop is one iteration). Sometimes, if the while expression evaluates to FALSE from the very beginning, the nested statement(s) won't even be run once." - php.net.&lt;br /&gt;&lt;br /&gt;Here is an example of using a "while" loop:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;PHP-Code:&lt;br /&gt;&lt;?php&lt;br /&gt;$number = 0;&lt;br /&gt;&lt;br /&gt;while ($number &lt; 10) {&lt;br /&gt;/* "while" $number is less than o 10 (&lt; 10) - Run the loop! */&lt;br /&gt;$number++;&lt;br /&gt;/* add "1" to the number */&lt;br /&gt;}&lt;br /&gt;echo $number; //prints "10" to the screen!&lt;br /&gt;&lt;br /&gt;?&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Now lets review the code. before the "while" loop starts we set the variable "$number" equal to ZERO. Then the while loop checks to see if "$number" is less than "10". If "$number" IS less than ten it runs the loop and adds "1" to the number, at this point "$number" now equals "1" and the loop starts over.&lt;br /&gt;&lt;br /&gt;Since "1" is still less than ten it will run the loop again and add another "1" to "$number". Now "$number" is equal to "2" and the loop starts over.&lt;br /&gt;&lt;br /&gt;Since "2" is still less than ten it will run the loop again and add another "1" to "$number"! Now "$number" is equal to "3" and the loop starts over again! etc, etc. until the variable "$number" is equal to "10" and equates to FALSE in the start of the while loop (10 &lt; 10 = FALSE). At that point the while loop is over and the next part of the code comes into play - outputting the value of "$number", which is ten.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Here are some more examples of control structures (loops) to help you better understand them:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;PHP-Code:&lt;br /&gt;&lt;?php&lt;br /&gt;$fruit = 'apple';&lt;br /&gt;if ($fruit == 'pear') {&lt;br /&gt;    echo "$fruit is a pear!";&lt;br /&gt;}&lt;br /&gt;elseif ($fruit == 'banana') {&lt;br /&gt;    echo "$fruit is a banana!";&lt;br /&gt;}&lt;br /&gt;else {&lt;br /&gt;    echo "then $fruit must be an apple because it is not a banana or pear!";&lt;br /&gt;}&lt;br /&gt;?&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;This would output the last 'else' statement because the first two Control Structures were FALSE.&lt;br /&gt;($fruit = 'apple', not 'banana' or 'pear'.)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;PHP-Code:&lt;br /&gt;&lt;?php&lt;br /&gt;$number = '1';&lt;br /&gt;while ($number &lt;= 100) {&lt;br /&gt;    echo $number. "";&lt;br /&gt;    $number++;&lt;br /&gt;}&lt;br /&gt;?&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;This would output the numbers from 1 to 100! While "$number" is less than or equal to 100 ($number &lt;= 100) - print it and add one to it. (I put a "" (HTML Line Break) in there just to put each number on a different line.)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;For more information please read these articles:&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4889431653894848295-8980308754124643643?l=domyat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://domyat.blogspot.com/feeds/8980308754124643643/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4889431653894848295&amp;postID=8980308754124643643' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4889431653894848295/posts/default/8980308754124643643'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4889431653894848295/posts/default/8980308754124643643'/><link rel='alternate' type='text/html' href='http://domyat.blogspot.com/2008/03/lesson-8-control-structures-2.html' title='Lesson 8 - Control Structures 2'/><author><name>elawael</name><uri>http://www.blogger.com/profile/11684828293686686914</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4889431653894848295.post-4322572256150766639</id><published>2008-03-31T08:16:00.002-07:00</published><updated>2008-03-31T08:17:49.598-07:00</updated><title type='text'>Lesson 7 - Control Structures</title><content type='html'>IF&lt;br /&gt;&lt;br /&gt;Today we will go over simple control structures. You can think of them as "forks in the road" of your code. Depinding on whether the control structures are true or false will determine what your code does next. Here is a simple example of a control structure:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;PHP-Code:&lt;br /&gt;&lt;?php&lt;br /&gt;if (expression = true)&lt;br /&gt; then do statement&lt;br /&gt;?&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;"If" checks to see if the expression is TRUE and if it is: the "if" will run the code below it. In other words - "If" an expression evaluates to TRUE, PHP will execute the following statement, and if it evaluates to FALSE - it'll ignore it.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The following example would display "2 is bigger than 1" (2 &gt; 1) if 2 IS bigger than 1:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;PHP-Code:&lt;br /&gt;&lt;?php&lt;br /&gt;if (2 &gt; 1) // if "2" is greater than (&gt;) "1"&lt;br /&gt; print "2 is bigger than 1";&lt;br /&gt;?&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;However, the following "if" statment would not do anything because it is FALSE:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;PHP-Code:&lt;br /&gt;&lt;?php&lt;br /&gt;&lt;br /&gt;if (1 &gt; 2) {&lt;br /&gt;/* (if "1" is greater than "2"). FALSE because 1 is smaller than 2&lt;br /&gt;*/&lt;br /&gt;print "1 is bigger than 2"; &lt;br /&gt;}&lt;br /&gt;?&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;More About "if":&lt;br /&gt;&lt;br /&gt;"Any PHP script is built out of a series of statements. A statement can be an assignment, a function call, a loop, a conditional statement of even a statement that does nothing (an empty statement). Statements usually end with a semicolon. In addition, statements can be grouped into a statement-group by encapsulating a group of statements with curly braces. A statement-group is a statement by itself as well.The if construct is one of the most important features of many languages, PHP included. It allows for conditional execution of code fragments. PHP features an if structure that is similar to that of C:" -PHP.net&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;PHP-Code:&lt;br /&gt;&lt;?php&lt;br /&gt;if (expression)&lt;br /&gt; then do statement&lt;br /&gt;?&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Now lets make a simple script that checks a number to see if it is to big, or if it is to small. Open your text editor (if you don't have one use Notpad) and save the blank file as "if.php" (with the quotes). Now write the following text in the file:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;PHP-Code:&lt;br /&gt;&lt;?php&lt;br /&gt;/* Make a new variable called "$cpu_number" and set it equal to "34". */&lt;br /&gt;$cpu_number = 34;&lt;br /&gt;/* Make a new variable called "$number" and set it equal to "50". */&lt;br /&gt;$your_number = 50&lt;br /&gt;&lt;br /&gt; If ($your_number &gt; $cpu_number) { &lt;br /&gt; /* "if" $your_number is greater than $cpu_number do the following: */&lt;br /&gt; echo "Your Number Is Bigger!";&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; If ($your_number &lt; $cpu_number) {&lt;br /&gt; /* "if" $your_number is less than $cpu_number do the following: */&lt;br /&gt; echo "Your Number Is Smaller!";&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;?&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;When you run the code you will see "Your Number Is Bigger!" on the screen because the first "if" statment equaled TRUE (50 is greater than 34) while the second "if" was FALSE (50 is less than 34), so only the first statment ran.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Now lets make it so that a user can enter a number and see if they have a bigger number. Change the code in "if.php" to the folowing:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;PHP-Code:&lt;br /&gt;&lt;form action="if.php" method="get"&gt; &lt;!--//Make the HTML Form --&gt;&lt;br /&gt;Your Number:&lt;input name="num" type="text"&gt; &lt;!--//Make the input box --&gt;&lt;br /&gt;&lt;input type="submit" value="Submit"&gt; &lt;!--//Make the Submit botton --&gt;&lt;br /&gt;&lt;/form&gt; &lt;!--// End the Form --&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;?php&lt;br /&gt;/* Make a new variable called "$cpu_number" and set it equal to "34". */&lt;br /&gt;$cpu_number = 50;&lt;br /&gt;&lt;br /&gt;/* "if" somthing was posted (isset) do the following: */&lt;br /&gt;if (isset($_GET['num'])) { &lt;br /&gt; $number = $_GET['num']; &lt;br /&gt; /*put the posted variable "num" into a new variable called "$number". */&lt;br /&gt; &lt;br /&gt; If ($number &gt; $cpu_number) {&lt;br /&gt; /* "if" $number is greater than $cpu_number do the following: */&lt;br /&gt; echo "Your Number Is Bigger!";&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; If ($number &lt; $cpu_number) {&lt;br /&gt; /* "if" $number is less than $cpu_number do the following: */&lt;br /&gt; echo "Your Number Is Smaller!";&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;?&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;When you save the file and upload it to your server you will be presented with a form where you can enter a number and see if it is higher or lower than the number the cpu chose.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;You will notice in the above example there are two "if" statements inside of another "if" statment:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;PHP-Code:&lt;br /&gt;&lt;?php&lt;br /&gt;if (isset($_GET['num'])) { &lt;br /&gt; $number = $_GET['num']; &lt;br /&gt; If ($number &gt; $cpu_number) {&lt;br /&gt; echo "Your Number Is Bigger!";&lt;br /&gt; }&lt;br /&gt; If ($number &lt; $cpu_number) {&lt;br /&gt; echo "Your Number Is Smaller!";&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;?&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If the first statment is TRUE PHP will go on to process the next two "if" statments. If the first "if" statment is FALSE PHP will ignore the other two "if" statements inside of the first. That is why you don't see anything when you first run the script - it equals FALSE untill you post some value!&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;For more information please read these articles:&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4889431653894848295-4322572256150766639?l=domyat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://domyat.blogspot.com/feeds/4322572256150766639/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4889431653894848295&amp;postID=4322572256150766639' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4889431653894848295/posts/default/4322572256150766639'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4889431653894848295/posts/default/4322572256150766639'/><link rel='alternate' type='text/html' href='http://domyat.blogspot.com/2008/03/lesson-7-control-structures.html' title='Lesson 7 - Control Structures'/><author><name>elawael</name><uri>http://www.blogger.com/profile/11684828293686686914</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4889431653894848295.post-3706354370492696780</id><published>2008-03-31T08:16:00.001-07:00</published><updated>2008-03-31T08:16:34.676-07:00</updated><title type='text'>Lesson 5 - GET and POST</title><content type='html'>One of the most powerful features of Dynamic Coding is the ability to pass values to new pages! You may have seen a URL like this before:&lt;br /&gt;&lt;br /&gt;Code:&lt;br /&gt;&lt;br /&gt;http://www.somesite.com/viewpage.php?art=24&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The last part of the URL("?art=24") is actually a variable being sent to the page! For example, the number "24" may be telling the page "viewpage.php" to show the article ("art=") number "24" on that page. Just like "viewpage.php?art=95" may be telling the page to show article (art) "95". (This will all make sense in a little bit.)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In PHP this is called "Posting" and can be done with the "$_GET[]" and "$_POST[]" Superglobals. This is what "$_GET[]" might look like:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;PHP-Code:&lt;br /&gt;$_GET['page_number'] &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In our above URL example I said that the URL probably was to get a certain article number and show it("?art=24"). Let's imagine that this is the case and write an imaginary script to get the "?art=24" variable at the end of the string.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;PHP-Code:&lt;br /&gt;&lt;?php&lt;br /&gt;$article = $_GET['art']; &lt;br /&gt;/*we are going to extract the "$_GET['art'];" &lt;br /&gt;Superglobal into a new variable called "$article".&lt;br /&gt; the value of the variable $article will be "24" &lt;br /&gt;because that is the value of the $_GET['art'] &lt;br /&gt;Superglobal. (Remember: viewpage.php?art=24 ) */&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;get_article($article); &lt;br /&gt;/*Then we submit the Variable&lt;br /&gt;"$article" to a function that goes and gets the value&lt;br /&gt;of "$article" - which, in this case, equals "24".&lt;br /&gt;So, in other words: you get the value of the posted "?art=" which is "24" and get the corresponding article! (article number 24!)*/&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Here is the code without the comments:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;PHP-Code:&lt;br /&gt;&lt;?php&lt;br /&gt;$article = $_GET['art'];&lt;br /&gt;get_article($article);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Now that wasn't to hard was it? ...was it??? :P. We got the value of 24 that was on the end of the ("viewpage.php?art=24") URL and got the corresponding article 24 from wherever it was.&lt;br /&gt;&lt;br /&gt;You could also write the code like this and skip putting the value of "$_GET" into a variable:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;PHP-Code:&lt;br /&gt;&lt;?php&lt;br /&gt;get_article($_GET['art']);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;I will give you one more example of using "$_GET". Suppose you are looking at a book online. There are 300 pages in that book and you are on page 12. This is what the URL might look like:&lt;br /&gt;&lt;br /&gt;Code:&lt;br /&gt;&lt;br /&gt;http://www.booksite.com/book.php?page=12&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Each page might have some code like this on it:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;PHP-Code:&lt;br /&gt;&lt;?php&lt;br /&gt;$book_page = $_GET['page']; /* "$book_page" is now equal to "12". (?page=12) */&lt;br /&gt;get_page($book_page);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Then you decide you want to skip 138 pages and go to page 150. Well, since book.php can be passed values why not edit the URL? If you go up to the address bar and rename the URL from&lt;br /&gt;&lt;br /&gt;Code:&lt;br /&gt;&lt;br /&gt;http://www.booksite.com/book.php?page=12&lt;br /&gt;To:&lt;br /&gt;http://www.booksite.com/book.php?page=150&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;You will be telling the page "book.php" to get page 150 (?page=150) instead of page 12 (?page=12).&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Note: This won't work on most sites because they have security measures to keep people from changing the posted values. However, it was useful to help you understand the "$_GET" variable better.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Now I will teach you about the "$_POST" Superglobal. "$_POST" is different from "$_GET" in that "$_POST" does not show the values being passed in the URL. "$_POST" Hides them in the "Headers" that are sent to the page. In every request that a browser like Firefox or IE makes, they send some information to the site that they are requesting the page from. Such as what the browsers name is and what the IP address they are coming from is, etc... They can also "Post" additional information along with the "Headers". Like what page of the book they are on.&lt;br /&gt;&lt;br /&gt;a "$_POST" URL looks like this:&lt;br /&gt;&lt;br /&gt;Code:&lt;br /&gt;&lt;br /&gt;http://www.booksite.com/book.php&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;with the page number a person is on, sent hidden in the Headers. "$_POST" is a more secure form of passing variables because the average user doesn't know what is going on behind the scenes. The PHP code used to get the posted values is almost identical to the PHP code needed to get the "$_GET" value:&lt;br /&gt;&lt;br /&gt;PHP-Code:&lt;br /&gt;&lt;?php&lt;br /&gt;$book_page = $_POST['page'];&lt;br /&gt;get_page($book_page);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If you want more information on both of these Superglobals. Please read these Tutorials:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;When you are done please proceed to the next lesson and we will make a script that gets passed different values!&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;For more information please read these articles:&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4889431653894848295-3706354370492696780?l=domyat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://domyat.blogspot.com/feeds/3706354370492696780/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4889431653894848295&amp;postID=3706354370492696780' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4889431653894848295/posts/default/3706354370492696780'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4889431653894848295/posts/default/3706354370492696780'/><link rel='alternate' type='text/html' href='http://domyat.blogspot.com/2008/03/lesson-5-get-and-post_31.html' title='Lesson 5 - GET and POST'/><author><name>elawael</name><uri>http://www.blogger.com/profile/11684828293686686914</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4889431653894848295.post-7280489190385748233</id><published>2008-03-31T07:54:00.001-07:00</published><updated>2008-03-31T07:54:55.810-07:00</updated><title type='text'>Lesson 5 - GET and POST</title><content type='html'>The $_GET and $_POST Superglobals.&lt;br /&gt;&lt;br /&gt;One of the most powerful features of Dynamic Coding is the ability to pass values to new pages! You may have seen a URL like this before:&lt;br /&gt;&lt;br /&gt;Code:&lt;br /&gt;&lt;br /&gt;http://www.somesite.com/viewpage.php?art=24&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The last part of the URL("?art=24") is actually a variable being sent to the page! For example, the number "24" may be telling the page "viewpage.php" to show the article ("art=") number "24" on that page. Just like "viewpage.php?art=95" may be telling the page to show article (art) "95". (This will all make sense in a little bit.)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In PHP this is called "Posting" and can be done with the "$_GET[]" and "$_POST[]" Superglobals. This is what "$_GET[]" might look like:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;PHP-Code:&lt;br /&gt;$_GET['page_number'] &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In our above URL example I said that the URL probably was to get a certain article number and show it("?art=24"). Let's imagine that this is the case and write an imaginary script to get the "?art=24" variable at the end of the string.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;PHP-Code:&lt;br /&gt;&lt;?php&lt;br /&gt;$article = $_GET['art']; &lt;br /&gt;/*we are going to extract the "$_GET['art'];" &lt;br /&gt;Superglobal into a new variable called "$article".&lt;br /&gt; the value of the variable $article will be "24" &lt;br /&gt;because that is the value of the $_GET['art'] &lt;br /&gt;Superglobal. (Remember: viewpage.php?art=24 ) */&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;get_article($article); &lt;br /&gt;/*Then we submit the Variable&lt;br /&gt;"$article" to a function that goes and gets the value&lt;br /&gt;of "$article" - which, in this case, equals "24".&lt;br /&gt;So, in other words: you get the value of the posted "?art=" which is "24" and get the corresponding article! (article number 24!)*/&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Here is the code without the comments:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;PHP-Code:&lt;br /&gt;&lt;?php&lt;br /&gt;$article = $_GET['art'];&lt;br /&gt;get_article($article);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Now that wasn't to hard was it? ...was it??? :P. We got the value of 24 that was on the end of the ("viewpage.php?art=24") URL and got the corresponding article 24 from wherever it was.&lt;br /&gt;&lt;br /&gt;You could also write the code like this and skip putting the value of "$_GET" into a variable:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;PHP-Code:&lt;br /&gt;&lt;?php&lt;br /&gt;get_article($_GET['art']);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;I will give you one more example of using "$_GET". Suppose you are looking at a book online. There are 300 pages in that book and you are on page 12. This is what the URL might look like:&lt;br /&gt;&lt;br /&gt;Code:&lt;br /&gt;&lt;br /&gt;http://www.booksite.com/book.php?page=12&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Each page might have some code like this on it:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;PHP-Code:&lt;br /&gt;&lt;?php&lt;br /&gt;$book_page = $_GET['page']; /* "$book_page" is now equal to "12". (?page=12) */&lt;br /&gt;get_page($book_page);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Then you decide you want to skip 138 pages and go to page 150. Well, since book.php can be passed values why not edit the URL? If you go up to the address bar and rename the URL from&lt;br /&gt;&lt;br /&gt;Code:&lt;br /&gt;&lt;br /&gt;http://www.booksite.com/book.php?page=12&lt;br /&gt;To:&lt;br /&gt;http://www.booksite.com/book.php?page=150&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;You will be telling the page "book.php" to get page 150 (?page=150) instead of page 12 (?page=12).&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Note: This won't work on most sites because they have security measures to keep people from changing the posted values. However, it was useful to help you understand the "$_GET" variable better.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Now I will teach you about the "$_POST" Superglobal. "$_POST" is different from "$_GET" in that "$_POST" does not show the values being passed in the URL. "$_POST" Hides them in the "Headers" that are sent to the page. In every request that a browser like Firefox or IE makes, they send some information to the site that they are requesting the page from. Such as what the browsers name is and what the IP address they are coming from is, etc... They can also "Post" additional information along with the "Headers". Like what page of the book they are on.&lt;br /&gt;&lt;br /&gt;a "$_POST" URL looks like this:&lt;br /&gt;&lt;br /&gt;Code:&lt;br /&gt;&lt;br /&gt;http://www.booksite.com/book.php&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;with the page number a person is on, sent hidden in the Headers. "$_POST" is a more secure form of passing variables because the average user doesn't know what is going on behind the scenes. The PHP code used to get the posted values is almost identical to the PHP code needed to get the "$_GET" value:&lt;br /&gt;&lt;br /&gt;PHP-Code:&lt;br /&gt;&lt;?php&lt;br /&gt;$book_page = $_POST['page'];&lt;br /&gt;get_page($book_page);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If you want more information on both of these Superglobals. Please read these Tutorials:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;When you are done please proceed to the next lesson and we will make a script that gets passed different values!&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;For more information please read these articles:&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4889431653894848295-7280489190385748233?l=domyat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://domyat.blogspot.com/feeds/7280489190385748233/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4889431653894848295&amp;postID=7280489190385748233' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4889431653894848295/posts/default/7280489190385748233'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4889431653894848295/posts/default/7280489190385748233'/><link rel='alternate' type='text/html' href='http://domyat.blogspot.com/2008/03/lesson-5-get-and-post.html' title='Lesson 5 - GET and POST'/><author><name>elawael</name><uri>http://www.blogger.com/profile/11684828293686686914</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4889431653894848295.post-4954587775042744147</id><published>2008-03-31T07:53:00.000-07:00</published><updated>2008-03-31T07:54:25.808-07:00</updated><title type='text'>Lesson 4 - First PHP File</title><content type='html'>Now we are going to put the topics we disscussed in lessons 1-3 into practice.&lt;br /&gt;&lt;br /&gt;When you make a PHP file you have to name it '*.php' just like microsoft word documents are named '*.doc' and some images are '*.jpg'. If you don't name a file '*.php' - the PHP core won't process it, and it won't work.&lt;br /&gt;&lt;br /&gt;Open up "notepad" (I use/recomend the free SciTE Text Editor becuase it HIGHLIGHTS the different code!)or some other simple text editor(NOT MS WORD, or WORD PERFECT) and type the following:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;PHP-Code:&lt;br /&gt;&lt;?php&lt;br /&gt;$site_name = "type some site of your own here";&lt;br /&gt;//the $site_name string&lt;br /&gt;$paragraph_text = "Type your welcome text here! type more text here!";&lt;br /&gt;// the first $paragraph string&lt;br /&gt;$email = 'type your@email.com';&lt;br /&gt;//your email string&lt;br /&gt;$your_age = 00;&lt;br /&gt;// your age variable&lt;br /&gt;?&gt;&lt;br /&gt;&lt;br /&gt;&lt;html&gt;&lt;br /&gt;&lt;body&gt;&lt;br /&gt;&lt;h2&gt;&lt;?php echo $site_name; ?&gt;&lt;/h2&gt;&lt;br /&gt;&lt;p&gt;&lt;?php echo $paragraph_text; ?&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Email me: &lt;a href="mailto:&lt;?php echo $email; ?&gt;"&gt;&lt;?php echo $email; ?&gt;&lt;/a&gt;&lt;br /&gt;&lt;/body&gt;&lt;br /&gt;&lt;/html&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Once you are finished typing the text above, select "file", "Save as" and name it "test.php" with the quotes. By naming a file with quotes you are telling the computer not to name it something ".txt". For example, if you just name it test.php (without the quotes) and save it, when you go to the file it will be named "test.php.txt"!&lt;br /&gt;&lt;br /&gt;Now upload the file to your web server (FTP). If you don't know how to use FTP (File Transfer Protocol) to put web pages onto the internet, please read FTP 101 - A Beginner's Guide or An Introduction to FTP and I recommend you use the free SmartFTP client.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If you are using "easyphp", "WAMP", or some other program/server on YOUR computer simply save or move the file to the correct folder (probably "C:\wamp\www\" or something like that.)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Once the file is in the correct place, point your browser to the location of the file and run it. If you are using a web server the file will be wherever you FTP'ed it to. (exmaple: "http://www.yoursite.com/test.php") If you are using a server on your own PC it should be something like "http://localhost/test.php"&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;when you run the page you should see this:&lt;br /&gt;&lt;br /&gt;Code:&lt;br /&gt;&lt;br /&gt;type some site of your own here&lt;br /&gt;Type your welcome text here! type more text here!&lt;br /&gt;Email me: type your@email.com&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If you hold your mouse over the page and "right-click" and select "view source" from the options - you will see this in the pop-up window:&lt;br /&gt;&lt;br /&gt;Code:&lt;br /&gt;&lt;br /&gt;&lt;html&gt;&lt;br /&gt;&lt;body&gt;&lt;br /&gt;&lt;h2&gt;type some site of your own here&lt;/h2&gt;&lt;br /&gt;&lt;p&gt;Type your welcome text here! type more text here!&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Email me: &lt;a href="mailto:type your@email.com"&gt;type your@email.com&lt;/a&gt;&lt;br /&gt;&lt;/body&gt;&lt;br /&gt;&lt;/html&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Where is all of the PHP code? Well PHP processed it all and then gave the result to the brower. It ran the php code and submitted the result to your computer to display. That is one of the beauties of PHP - No one knows what you type! No one can steal your code (javascript) and no one can "beat the system" by knowing what you are doing behind the scenes on your web site - so you are safer from hackers (As opposed to other languages).&lt;br /&gt;&lt;br /&gt;If you want a challenge make a file named "address.php" that prints your address from three different strings: (your name, street, and city/state/zip).&lt;br /&gt;&lt;br /&gt;Here is another php file that prints your Full Name:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;PHP-Code:&lt;br /&gt;&lt;?php&lt;br /&gt;$first_name = "John";&lt;br /&gt;$second_name = "M.";&lt;br /&gt;$last_name = "Doe";&lt;br /&gt;?&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;html&gt;&lt;br /&gt;&lt;body&gt;&lt;br /&gt;&lt;h2&gt;&lt;?php echo "$first_name $second_name $last_name"; ?&gt;&lt;/h2&gt;&lt;br /&gt;&lt;/body&gt;&lt;br /&gt;&lt;/html&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Now that you know what a "string" is - we can start doing some fun things with them!&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;For more information please read these articles:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4889431653894848295-4954587775042744147?l=domyat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://domyat.blogspot.com/feeds/4954587775042744147/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4889431653894848295&amp;postID=4954587775042744147' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4889431653894848295/posts/default/4954587775042744147'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4889431653894848295/posts/default/4954587775042744147'/><link rel='alternate' type='text/html' href='http://domyat.blogspot.com/2008/03/lesson-4-first-php-file.html' title='Lesson 4 - First PHP File'/><author><name>elawael</name><uri>http://www.blogger.com/profile/11684828293686686914</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4889431653894848295.post-5566971859105799425</id><published>2008-03-31T07:52:00.000-07:00</published><updated>2008-03-31T07:53:28.116-07:00</updated><title type='text'>Lesson 3 - Strings</title><content type='html'>Strings&lt;br /&gt;&lt;br /&gt;Strings in PHP could be thought of as sentences such as: "I went to the store". Strings differ from variables in that they are a COLLECTION of values in one variable.&lt;br /&gt;Example:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;PHP-Code:&lt;br /&gt;$variable = '9';&lt;br /&gt;$string = 'abcdefghijklmnopqrstuvwxyz'; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Stings can be used to store names, tiles, addresses, and all kinds of things. So expect to use them often! Just like variables - you don't need to tell the computer that it is a "string". The computer can tell just by what value you put in it.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;PHP-Code:&lt;br /&gt;$1 = 0; //var&lt;br /&gt;$2 = 'Hi'; //string&lt;br /&gt;$3 = "Fast Monkey"; //string&lt;br /&gt;$4 = 'K'; //var &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Now, what you can DO with strings is the cool part! (For a list of all string functions click here.)&lt;br /&gt;&lt;br /&gt;Some of the more important string functions are:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The strlen(); Function.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The explode(); Function.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The str_replace(); Function.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The str_split(); Function.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The strip_tags(); Function.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;I highly recomend you read Codewalkers String Primer.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Here are some links to help you learn more about strings:&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4889431653894848295-5566971859105799425?l=domyat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://domyat.blogspot.com/feeds/5566971859105799425/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4889431653894848295&amp;postID=5566971859105799425' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4889431653894848295/posts/default/5566971859105799425'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4889431653894848295/posts/default/5566971859105799425'/><link rel='alternate' type='text/html' href='http://domyat.blogspot.com/2008/03/lesson-3-strings.html' title='Lesson 3 - Strings'/><author><name>elawael</name><uri>http://www.blogger.com/profile/11684828293686686914</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4889431653894848295.post-3815839162010824324</id><published>2008-03-31T07:40:00.000-07:00</published><updated>2008-03-31T07:43:28.489-07:00</updated><title type='text'>Lesson 2 - PHP Code</title><content type='html'>&lt;span class="postbody"&gt;If you visited the link in the last lesson you probably already know how to tell PHP code and how to comment it. Never the less, I want to make sure and go over it just so that no one is confused.&lt;br /&gt;&lt;br /&gt;This is what PHP code looks like by itself:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;  	  &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt; 	&lt;/tr&gt; 	&lt;tr&gt; 	  &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;&lt;/td&gt; --&gt; 	  &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;...(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;more code&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)....&lt;br /&gt; ...(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;more code&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)....&lt;br /&gt; echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"$$var dollars spent."&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt; ...(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;more code&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)....&lt;br /&gt; ...(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;more code&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;).... &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt; 	&lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Everything between the opening "&lt;?php" &amp;amp; "?&gt;;" tags is sent to the PHP core to be processed, then the result is sent back. and the rest of the page continues to load. Here is what PHP code might look like in an HTML file:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="90%"&gt;&lt;tbody&gt;&lt;tr&gt; 	  &lt;td&gt;&lt;span class="genmed"&gt;&lt;b&gt;Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;	&lt;/tr&gt;	&lt;tr&gt;	  &lt;td id="code"&gt;&lt;br /&gt;&lt;html&gt;&lt;br /&gt;&lt;head&gt;&lt;br /&gt;&lt;title&gt;&lt;?php echo $tile; ?&gt;&lt;title&gt;&lt;br /&gt;&lt;/head&gt;&lt;br /&gt;&lt;body&gt;&lt;br /&gt;&lt;?php echo "Welcome to $sitename"; ?&gt;&lt;br /&gt;&lt;p&gt;We are committed to serving you!&lt;/p&gt;&lt;br /&gt;&lt;/body&gt;&lt;br /&gt;&lt;/html&gt;&lt;br /&gt;&lt;/td&gt;	&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;Don't worry if you don't understand it, this is just so you know what to expect.&lt;br /&gt;&lt;br /&gt;Another important part of programming is to document your code. Imagine trying to find a function or variable in a 1000 line PHP document! Without any human comments in the file it could take you forever to find what you were looking for. Here are the two most common forms of placing "Human Readable" text in a program:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;  	  &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt; 	&lt;/tr&gt; 	&lt;tr&gt; 	  &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;&lt;/td&gt; --&gt; 	  &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// two forward slashes tell the program to ignore what is behind them on the line. &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt; 	&lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;  	  &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt; 	&lt;/tr&gt; 	&lt;tr&gt; 	  &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;7&lt;br/&gt;&lt;/td&gt; --&gt; 	  &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;/*&lt;br /&gt;This is how you "comment" multiple lines in something.&lt;br /&gt;Everything between the opening "/*" and closing "*/&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;" is&lt;br /&gt;Ignored by the program. This form is more common than the&lt;br /&gt;"&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//" (Double-backslash) because unlike the other form this&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;one is not limited to only ONE line of text&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;.&lt;br /&gt;*/ &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt; 	&lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;The text in both of these "comments" is ignored by PHP. Here is an example of using them in a script:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;  	  &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt; 	&lt;/tr&gt; 	&lt;tr&gt; 	  &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;2&lt;br/&gt;3&lt;br/&gt;4&lt;br/&gt;5&lt;br/&gt;6&lt;br/&gt;7&lt;br/&gt;8&lt;br/&gt;9&lt;br/&gt;&lt;/td&gt; --&gt; 	  &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;/* CONFIGURATION of connect to DATABASE SECTION*/&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$servername&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'localhost' &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Replace 'localhost' with your server name&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$database_username&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'root'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Replace 'root' with your username&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$database_password&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'password'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Replace 'password' with your password&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$database_name&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'database_1'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Replace 'database_1' with your database name&lt;br /&gt;&lt;br /&gt;/* take all of the values and connect to the database */&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;mysql_connect&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$servername&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$database_username&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$database_password&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;mysql_select_db&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$database_name&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;); &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt; 	&lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;See how the comments help to describe what to do here? While you probably don't know what these functions are; you can get a general idea of what this script does thanks to comments in the code.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;One thing you need to understand before we go any further is the concept of "variables". (If you are a programmer you probably already have a knowledge of variables. Therefore you are welcome to skip this intro.)&lt;br /&gt;&lt;br /&gt;&lt;a href="http://en.wikipedia.org/wiki/Variable" target="_blank" class="postlink"&gt;Wikipedia.org&lt;/a&gt; describes a variable as: "...a place to store a value in computer memory." A variable is stored in a "byte" (or collection of bytes) in the computers memory. Variables store some value like a phone number or age in the bytes. Most computers now-a-day have about 256MB (Mega-bytes of memory) which is 256,000,000 bytes (Mega means "million").&lt;br /&gt;&lt;br /&gt;If I have lost you I apologize. Maybe you can understand variables better if I relate them to P.O. Boxes at the post office. There are many different P.O. boxes (Think "variables")in your post office. At any time they could be used to store many different pieces of information - your paycheck, a letter from grandma, a warrant of arrest for that guy down the street...ANYTHING. Therefore they are like variables, they store different pieces of information and what they hold can change from day to day.&lt;br /&gt;Here is what a variable in PHP looks like:&lt;br /&gt;Example:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;  	  &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt; 	&lt;/tr&gt; 	&lt;tr&gt; 	  &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;&lt;/td&gt; --&gt; 	  &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$variablename&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt; 	&lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;Right now there is nothing in the variable "$variablename". So lets add something..&lt;br /&gt;Example:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;div align="center"&gt; &lt;div style="overflow: auto; width: 90%;"&gt; &lt;table align="center" border="0" cellpadding="3" cellspacing="1" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;  	  &lt;td colspan="1"&gt;&lt;span class="genmed"&gt;&lt;b&gt;PHP-Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt; 	&lt;/tr&gt; 	&lt;tr&gt; 	  &lt;!-- &lt;td align="right" class="code" style="width: 5px; color: #dee6ec; border-right: none;"&gt;1&lt;br/&gt;&lt;/td&gt; --&gt; 	  &lt;td id="code"&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$variablename &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'John'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt; 	&lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;span class="postbody"&gt;&lt;br /&gt;&lt;br /&gt;Now the variable "$variablename" holds the value "John". Think of it like this: If you opened up "$variablename" you would find the word "John" inside! (Just like PO Box "204" holds a postcard.) "Capitalization is very important in PHP. It is generally a good idea to have all variables be entirely lowercase, and only use alphanumeric characters along with underscores (_) if necessary. $greeting is not the same as $Greeting, so it is important to remain consistent and watch the typos." -&lt;a href="http://www.tfproject.org/tfp/archive/index.php/t-33907.html" target="_blank" class="postlink"&gt;seretogis&lt;/a&gt; Below is a list of links for you to follow so that you can learn the syntax of the PHP variables and how to use them. These are the best tutorials I have found so have fun and see you in lesson 3!&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; &lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4889431653894848295-3815839162010824324?l=domyat.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://domyat.blogspot.com/feeds/3815839162010824324/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4889431653894848295&amp;postID=3815839162010824324' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4889431653894848295/posts/default/3815839162010824324'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4889431653894848295/posts/default/3815839162010824324'/><link rel='alternate' type='text/html' href='http://domyat.blogspot.com/2008/03/lesson-2-php-code.html' title='Lesson 2 - PHP Code'/><author><name>elawael</name><uri>http://www.blogger.com/profile/11684828293686686914</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4889431653894848295.post-1610249586547487560</id><published>2008-03-31T07:37:00.000-07:00</published><updated>2008-03-31T07:39:26.992-07:00</updated><title type='text'>Welcome to Beginning PHP!</title><content type='html'>&lt;span class="postbody"&gt; So you have decided to start learning one of the most powerful Internet programming languages there is - Congratulations! Welcome to Beginning PHP, My name's David and together we will start discovering why over 22 million websites use PHP to generate amazing dynamic pages.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;So what is PHP?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;PHP was created in 1995 by an independent software developer named Rasmus Lerdorf. His first PHP script was a Perl/CGI program that kept a log of each visitor that came to his site. The script then displayed how many visits he had received on each page. He soon started receiving emails from other web masters across the Internet asking how he did this (a "Counter" as this is called, were very rare back then.) Because of the interest in his script he started to develop PHP into a new language, by adding more and more features to his script. Eventually, he decided to stop programming PHP in Perl/CGI, and start constructing it with a more powerful language, "C". Thus the interest in PHP keep growing as more features were added and soon other people started writing code for it. It is now one of the most popular languages on the Internet, with contributing programmers across the world.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Should I learn PHP?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;As long as you want to...YES! There is not a person I can think of that would not benefit from the ability to post their own dynamic resume online, or have the capability to list their products or services on the World Wide Web (www). With knowledge of PHP you could do everything from running an Ebay Clone, to managing a Photography site, to building the next Xanga. Don't get me wrong though, you don't have to start the next Hotmail to find a use for PHP! It is just as important for giving small sites the leverage to succeed online.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Anything I should know before I start this course?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Yes - HTML. HTML (Hypertext markup Language) is the simplest formatting language on the web. While PHP, Perl, ASP, and others transfer and process information, HTML makes it look good. For example, think of Microsoft Word. What you type into Word is similar to the function that PHP serves - it supplies the data. But just typing text into MS Word doesn't look very good. That is where the formatting features of Word come in. You can change the size, color, position, and look of the text in your document with the features of MS Word. That is what HTML does.&lt;span style="font-weight: bold;"&gt;HTML makes the information that you output from PHP look good.&lt;/span&gt;&lt;br /&gt;So that is why I recommend having a basic knowledge of HTML. If you don't know it already here are some good sites to help you learn this basic language.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;What do I need?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This is a big question and mostly depends on how skilled you are with other aspects of the computer. PHP requires the core interpreter and function libraries that you have to get from &lt;a href="http://www.php.net./" target="_blank"&gt;www.php.net.&lt;/a&gt; No, window's does NOT come ready for PHP programming. (Some Linux distributions do however.) This leaves you with four choices when it comes to setting up the PHP language so that you can start programming.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Install and compile the binary distributions for PHP and/or "Apache" web server on your machine. (Advanced) visit &lt;a href="http://www.php.net/" target="_blank" class="postlink"&gt;php.net&lt;/a&gt; for more information.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Install EasyPHP from &lt;a href="http://www.easyphp.org/" target="_blank" class="postlink"&gt;EasyPHP.org&lt;/a&gt;. (Easy, but only features PHP 4 and has some problems with Advanced Programs/scripts.) &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Install WAMP (Windows Apache MySQL PHP) or LAMP (Linux Apache MySQL PHP) on your own machine, or better yet, on some OTHER machine on YOUR network. If you are on windows you can visit &lt;a href="http://www.wampserver.com/" target="_blank" class="postlink"&gt;wampserver.com&lt;/a&gt; and download the newest release. (Intermediate) &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The way I Recommend: Buy some web space on a server that supports PHP and MySQL. (about $5-10 dollars a month). I highly recommend &lt;a href="http://www.1and1.com/?k_id=8532941" target="_blank" class="postlink"&gt;1and1.com&lt;/a&gt;. They are like the "walmart" of hosting companies. (The largest in the world) they offer hosting for as low as $2.99 a month for 5 Gigabytes of space and 10 MySQL Databases!!! Don't worry they don't skimp on features ether! (Free Domain and ".htaccess" support!)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;After all, if you are learning PHP you are going to be using it anyway... so you might as well buy hosting space and a domain now before the name is taken. If you already have a web site your hosting company may already have PHP install on your server. (Call/Email them to be sure.)&lt;br /&gt;If you don't want to pay for web space but want to put a site online I recommend that you look into some free hosting options like &lt;a href="http://www.100webspace.com/freeplan.html" target="_blank" class="postlink"&gt;100webspace.com&lt;/a&gt; or &lt;a href="http://www.dotgeek.org/" target="_blank" class="postlink"&gt;Dot Geek&lt;/a&gt; - or just choose the one that fits you from these lists: &lt;a href="http://www.0php.com/free_PHP_webhosting.php" target="_blank" class="postlink"&gt;PHP Free Hosting List&lt;/a&gt; and &lt;a href="http://www.oinko.net/freephp/" target="_blank" class="postlink"&gt;PHP MySQL Free Hosting List&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;But be cautious - they all have their non-monetary price!&lt;/span&gt;&lt;br /&gt;Personally... I started out with Easyphp. It is a snap to install (it's an .exe file) and will get you running fast. It worked great while I was learning PHP and coding small scripts. Then I shopped around and after looking at many different hosting companies like "BlueHost" and "godaddy" I finally chose &lt;a href="http://www.1and1.com/?k_id=8532941" target="_blank" class="postlink"&gt;1and1.com&lt;/a&gt; for a place on the internet to host my first site. Recently I deleted Easyphp as I needed more power for my advanced scripts and took an old computer and installed XP and WAMP on it so that I can build and test my sites on my own personal network and then upload the files to 1and1. So the choice is yours, just 
