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

(singke) #1

Listing 20.6 Converting Script to Be Completely PHP


<?
print("\n");
print("\n");
print("Listing 20.6\n");
print("\n");


$Hour = date("H");
$Intensity = round(($Hour/24.0)*(0xFF));
$PageColor = dechex($Intensity).
dechex($Intensity).
dechex($Intensity);


print("<BODY BGCOLOR=\"#$PageColor\">\n");
print("

Listing 20.6

\n");
print("\n");
print("\n");
?>


Separating HTML from PHP


The last approach I want to discuss involves using the include and require
functions. As you may recall from Chapter 8, "I/O Functions," these functions
include a file in the PHP code. The file is considered to be a PHP file, regardless of the
extension on the name. If PHP code appears in the included file, it is surrounded in <?
and ?> tags. You may want to turn back to the functional reference to refresh yourself on
the differences between include and require , but they aren't particularly important
to this discussion.


Certain chunks of HTML must appear on every well-formed page. Additionally you may
develop repeating elements such as a company logo. Rather than write them into every
page, you may choose to put them into a file and dynamically include them. Listing
20.7 contains HTML you might include at the top of every page on a site. In Listing
20.8 are two lines to close a page. Listing 20.10 wraps the content in Listing 20.9
with the opening and closing code to form a complete page.


Listing 20.7 Start of HTMLPage




PHP


Listing 20.8 End of HTML Page

Free download pdf