LIGHTENING YOUR WORKLOAD WITH (Web design software) INCLUDES You now have

LIGHTENING YOUR WORKLOAD WITH INCLUDES You now have the basis for automatically creating the page title for every page in your site, using basename(), $_SERVER[’SCRIPT_NAME’], and an include file. 3. Create a new PHP file called title.inc.php and save it in the includes folder. 4. Strip out any code inserted by your script editor, and type in the following code (the finished code for title.inc.php is in the ch04/includes folder of the download files): This finds the filename of the current page, strips the .php filename extension, and assigns the result to a variable called $title. The code for this include file must be enclosed in PHP tags. This is because the whole file needs to be treated as PHP. Unlike the menu, it won t be displayed directly inside other pages. 5. Open a PHP page in your script editor. If you re using the Japan Journey site, use contact.php. Include title.inc.php by typing this above the DOCTYPE declaration: 6. Amend the This uses echo to display — (the numerical entity for an em dash) followed by the value of $title. Because the string is enclosed in double quotes, PHP displays the value of $title (see All you ever wanted to know about quotes and more in Chapter 3 for an explanation of how PHP treats variables inside double quotes). The variable $title has also been enclosed in curly braces because there is no space between the em dash and $title. Although not always necessary, it s a good idea to enclose variables in braces when using them without any whitespace in a double-quoted string, as it makes the variable clear to you and the PHP engine. The first few lines of your page should look like this:
In case you need quality webspace to host and run your web applications, try our personal web hosting services.

Leave a Reply