The static principle of PHP template

Source: Internet
Author: User
Tags php template vars

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
  1. <?php
  2. If a static page already exists, read it directly and display
  3. if (file_exists (' index.html '))
  4. {
  5. echo file_get_contents (' index.html ');
  6. }
  7. Else
  8. {
  9. //The required variables are attached to the values here.
  10. $var = "Hello,world.";
  11. //Turn on output caching
  12. Ob_start ();
  13. //Call the template here, embed some PHP tags in the template, to display the value of the variable
  14. require_once (' template.php ');
  15. //Get the output cache here, that is, after the template is called, the future will be displayed to the content on the page
  16. $out = ob_get_contents ();
  17. //Save the content you want to display as a file
  18. file_put_contents (' index.html ',$out);
  19. //Output
  20. Ob_end_flush ();
  21. }


template.php

PHP code
  1. <! DOCTYPE HTML public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd ">
  2. "http://www.w3.org/1999/xhtml" >
  3. <meta http-equiv="Content-type" content= "text/html; Charset=utf-8 "/>
  4. <title>HTML</title>
  5. <body>
  6. <p>
  7. <?php echo $var;? >
  8. </p>
  9. </body>


The code explanation is shown in comments.  

Transfer from http://baiyuxiong.iteye.com/blog/796644

The static principle of PHP template

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.