PHP page static principle, with minimal code to explain the page static
How to apply: It is a good way to execute code when inserting or updating data to a database. For example: When PHP executes the Add () method (that is, when inserting data)
1 //Turn on caching2 Ob_start ();3 4 //Get HTML templates5$tmp _html =file_get_contents (' Template.tpl ');6 //Replace the files in the template7$php _content = Str_replace ("{", "<?")php echo ", $tmp _html);8$php _content = Str_replace (")", "?>", $tmp _html);9 Ten //output new content to a PHP file One file_put_contents ($phpfilename, $php _content); A - //when the file is included, it will be output, which is not <?php?> and other PHP related characters, but because the Ob_start is turned on, it will be output to the cache - Include "$phpfilename"; the //get the contents of the page from the cache, the content of this time is not <?php?> and other PHP related characters, completely into the HTML -$html _content =ob_get_contents (); - //output content to an HTML file - file_put_contents ($htmlfilename, $html _content); + - //Turn off caching +Ob_clean ();