PHP OB implements page static

Source: Internet
Author: User

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 ();

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.