Read some of the open source system, a simple summary of the PHP template and static principle.
Paste the code first, then explain.
index.php
PHP code
- <?php
- If a static page already exists, read it directly and display
- if (file_exists (' index.html '))
- {
- echo file_get_contents (' index.html ');
- }
- Else
- {
- //The required variables are attached to the values here.
- $var = "Hello,world.";
- //Turn on output caching
- Ob_start ();
- //Call the template here, embed some PHP tags in the template, to display the value of the variable
- require_once (' template.php ');
- //Get the output cache here, that is, after the template is called, the future will be displayed to the content on the page
- $out = ob_get_contents ();
- //Save the content you want to display as a file
- file_put_contents (' index.html ',$out);
- //Output
- Ob_end_flush ();
- }
template.php
PHP code
- <! DOCTYPE HTML public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd ">
- "http://www.w3.org/1999/xhtml" >
- <meta http-equiv="Content-type" content= "text/html; Charset=utf-8 "/>
- <title>HTML</title>
- <body>
- <p>
- <?php echo $var;? >
- </p>
- </body>
The code explanation is shown in comments.
Transfer from http://baiyuxiong.iteye.com/blog/796644
The static principle of PHP template