PHP using OB

Source: Internet
Author: User

Ob_start ([string output_callback])-Open output buffer

All output information is not sent directly to the browser, but is stored in the output buffer, which is used to process output information.

Ob_end_flush-End (send) the contents of the output buffer, turn off the output buffer

Using the output control function allows you to give free rein to the data in your script, which is useful when we want to output it before the header.

The code is as follows: <?php
Ob_start (); Open buffer
echo "Output n"; Output
Header ("header information");
Ob_end_flush ()//output all content to browser
?>



The personal use of OB is mostly when generating static HTML, when a page does not refresh, and when other users browse the page again, the program will no longer invoke PHP and related database tutorials. It is good practice to use OB to generate HTML at this time.

The code is as follows: <?php
Ob_start ();
if (@readfile ($tem _path)) {//writes the contents of the specified path to the cache. If there is no return false (that is, a PHP file that you want to convert to HTML)
$content = Ob_get_contents (); Get what's in the cache
$fp = fopen ("1.html", "w"); Create a file and open it, ready to write
Fwrite ($fp, $content); Write the contents of the PHP page to 1.html
}
Fclose ($FP);
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.