If you are constructing a dynamic site using PHP (See "Separating Content from Design," earlier in this chapter) or using PHP for other programmatic purposes on your site, it makes sense to use the PHP include mechanism.
"Whatever technology you use to serve your site, it undoubtedly has an include mechanism that works pretty much like server-side includes and PHP includes ."Most Linux and Apache based web hosts provide PHP scripting automatically for files named with a .php file extension. Within these files, PHP includes work almost exactly like server-side includes.
For example, suppose you have a simple little web home page in a file named index.php:
If you put the CSS styles for the elements of the web site such as the appearance of web site text in a file named style.inc, it can be included in PHP code like this:The code for the top portion of a page, to be shared in common across the site, might be put in a file named top.inc. It could now be inserted at the top of the body of a content page using the PHP include directive:
As with the server-side include example, if all the pages in a site use the PHP directives to include style.inc and top.inc, then site styles and the top element can be changed globally just by changing the contents of these include files.
Note that you can include PHP codeincluding other PHP include directiveswithin PHP includes and that there is no requirement that includes be named with any particular file suffix.
0 Comments:
Post a Comment