Using the PHP page static steps

Source: Internet
Author: User
This time to bring you the use of the PHP page static steps in detail, the use of the PHP page static considerations are what, the following is the actual case, together to see.

Page static, as the name implies is to convert the dynamic PHP into static HTML, the process such as

User Access index.php, if there is index.html and within the validity period, then output index.html directly, otherwise to generate index.html

File_put_contents () output static file

Ob_start () to open the PHP buffer

Ob_get_contents () Get buffer contents

Ob_clean () Empty buffer

Ob_get_clean () equivalent to Ob_get_contents () +ob_clean ()

code example

<?phpif (File_exists ('./html/index.html ') && time ()-Filectime ('./html/index.html ') <) {Require_once './html/index.html ';}  else {//Introduce database Configuration Require_once "./config/database.php";//Introduce Medoo class library require_once "./libs/medoo.php";//Instantiate db object $db = new Medoo ($config); Get Data $users = $db->select (' user ', [' uid ', ' username ', ' email '); Introduction of Template Require_once "./templates/index.php"; Write HTML File_put_contents ('./html/index.html ', ob_get_contents ());}

Believe that you have read the case of this article you have mastered the method, more exciting please pay attention to the PHP Chinese network other related articles!

Recommended reading:

PHP class reflection implementation of dependency injection steps

How PHP unlink and rmdir delete files in a directory

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.