The PHP code is all saved to a separate file, which is the file that is actually called by the page URL. The Web server parses the file through the PHP engine and returns the results to the browser. In general, PHP code always dynamically generates page content, such as querying a database or performing some sort of calculation. Here is an example:
example.php
Require (' class. Fasttemplate.php ');
$TPL = new Fasttemplate ('. ');
$TPL->define (' main ' = ' main.htm ',
' Header ' = ' header.htm ',
' LeftNav ' = ' leftnav.htm ');
The PHP code settings here $content to include the appropriate page content
$tpl->assign (' CONTENT ', $content);
$tpl->parse (' header ', ' header ');
$tpl->parse (' LeftNav ', ' leftnav ');
$TPL->parse (' main ', ' main ');
$tpl->fastprint (' MAIN ');
?>
Here we are using the popular Fasttemplate template class, but the basic idea is the same for many other template classes. First you instantiate a class, tell it where to look for the template file and which template file corresponds to which part of the page, then generate the page content, assign the result to the identifier of the content, and then parse each template file in turn, the template class will perform the necessary substitution operations, and finally output the parsing results to the browser.
This file is completely composed of PHP code, does not contain any HTML code, this is its biggest advantage. Now, PHP programmers can focus on writing code that generates page content, rather than worrying about how to generate HTML to properly format the final page.
You can use this method and the above file to construct a complete Web site. If the PHP code generates page content based on the query string in the URL, such as http://www.foo.com/example.php?article=099, you can construct a full magazine website accordingly.
It is easy to see that there is a second benefit to adopting a template. As shown in the example above, the navigation bar on the left side of the page is saved separately as a file, and we can simply edit this template file to change the navigation bar on the left side of all pages of the site.
http://www.bkjia.com/PHPjc/315436.html www.bkjia.com true http://www.bkjia.com/PHPjc/315436.html techarticle The PHP code is all saved to a separate file, which is the file that is actually called by the page URL. The Web server parses the file through the PHP engine and returns the results to the browser. ...