|
home—lects—exams—hws
D2L—breeze (snow day)
From PHP Visual Quickstart Guide by Larry Ullman
Based on notes by Jack Davis (jcdavis@radford.edu)
Tip: Minimize unmatched tags within an included file — it makes the fragments more re-usable in more contexts. Also, editing tools, parsers, etc. will be better able to work with those files. (For example, my editor's keyword-coloring and auto-indenting gets goofed up if I'm working with a inc file which has unmatched tags.)
So rather than:
<?php require('header-inc.php'); // This file includes '<html><head>..</head><body>', with dangling '<body>') ?> <p> My page-specific content. </p> <?php require('footer-inc.php'); // This file ends with '<body><html>') ?> |
<?php require('doctype-inc.php'); ?> <html> <?php require('header-inc.php'); // This file includes <head>...</head>') ?> <body> <?php require('page-top.php'); // This file includes a banner.) ?> <p> My page-specific content. </p> <?php require('footer-inc.php'); // This file includes contact-info ?> <body> <html> |
Also, it's nice to have the file for each page containing nothing more than one header/closer file without presuming any sort of page structure.
Though even in this case, consider using some framework to keep your page-source well organized/separated, and then write scripts to transform this into an efficient, optimized server arrangment. For example, each page's content might be entirely standalone frame, and the build system creates end files which combines that with header/footer/navigation files appropriately.
print CURRENCY; print "468 CURRENCY"; # Just a string literal — won't print the value of the constant print '468 ' . CURRENCY; # Will print the value of CURRENCY. |
One can also use the html header to specify the cache-expiration date of a page. (Helpful when appropriate — it lets browsers use cache in response to 'back' button.)
home—lects—exams—hws
D2L—breeze (snow day)
©2012, Ian Barland, Radford University Last modified 2012.Mar.16 (Fri) |
Please mail any suggestions (incl. typos, broken links) to ibarlandradford.edu |