Microsoft Word - Core PHP Programming Using PHP to Build Dynamic Web Sites

(singke) #1

This is an example of using a function to repeat
a commonly-used piece of HTML code.



<? PrintTitle("how it works"); ?>
Any time a title needs to be created, the
PrintTitle
function is called with the text of the title.



<? PrintTitle("advantages"); ?>
The code is more readable

Less text to type for each title

Easy to change every title




The page in Listing 20.3 is a very simple submission form. Each of the input tags will
be turned into a PHP variable when the submit button is clicked. This calls the script
listed in Listing 20.4. A file named req.txt will be opened for appending, and each
of the form fields will be written into the file. Each field is separated by tab characters,
which allows you to import the file into a spreadsheet easily.


Listing 20.2 Dressing Up CGI Output




Listing 20.2


Color Chart


The following chart displays the colors
safe for displaying in all browsers. These
colors should not dither on any computer
with a color palette of at least 256
colors.


This chart will only display on browsers
that support table cell background colors.


$color = array("00", "33", "66", "99", "CC", "FF");

for($Red = 0; $Red count <($color); $Red++)
{
print("

\n");


for($Green = 0; $Green count <($color);
$Green++)
{
print("

\n");