Day Two: Generating HTML With PHP

As we saw in day one (Power HTML) we learned that HTML is a simple mark up language for creating documents with hyperlinks. With simple HTML, you can create wonderful, informative web pages. The contents of such simple pages, however, are set in stone. If you want to get to the next level and make dynamic web pages, you will need a stronger tool...you will want to create a program that writes HTML

PHP Resources

PHP is part of the open source movement. As a result, you can find a tremendous amount of resources online. You can find a full, downloadable versions of the PHP documentation at php.net and phpBuilder.com. The online documentation is great as it includes comments by the PHP community.

There are quite a few books on coding in PHP. I like the big fat Professional PHP programming manual. This book works great as both a reference and training manual. 

PHP is an easy to learn server side scripting language. It is a program for generating web pages. In its original release, PHP stood for Personal Home Page. That's right, the base of the language was pounded out by a web page author who wanted to add interactive features to his personal web site. (Today programmers pretend the name stands for "PHP: Hypertext Preprocessor")

The open source movement latched onto the program. Added a number of enhancements, and their work evolved into the language that we know today. 

Since PHP was written by web designers for web designers. It evolved into a language that is both easy to learn and is optimized for the web page creation.

How PHP Works

A web server is a rather simple beast. Its primary mission is to read files from the disk and toss the contents of the file into cyberspace.

For static web pages, this process is simply a matter of reads and writes. PHP adds functionality on the web site. On the PHP enabled web site, the server reads the file from the client, and executes any PHP script on the page. It then sends the resulting HTML to the browser.

PHP script uses the delimiter <?php to start the script ?> to end the script. The script <?php echo "<b>Hello World</b>"; ?> produces the HTML code <b>Hello World</b>.

This simple combination of PHP and HTML allows you to add dynamic elements to pre-existing web pages. The fact that PHP integrates easily with your existing pages is one of the primary selling points of the language. 

One of the most useful features of PHP is the server side include. Rather than writing new PHP code for each page, you can save all of your PHP in a separate file and include it in multiple files. For example, I could publish all of my PHP in the file myphp.php, then reference it in web pages with the code <?php include("myphp.php); ?>

Server Side Includes are extremely useful for the formatting elements of your documents and menu bars. If you include all of your formatting elements in a server side include file, you will be able to change the look and feel of your web site by changing only one file.

Now, PHP is a full programming language. To master the language, you will need to learn about variables, operators, functions and all that stuff. I wrote a handy PHP manual that you may want to print out and read.

To complete this section, we need to first read the manual, then do the exercises. 

index -- next
math, plusroot, search, rgreetings, sponsors