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