PHP using OB

Source: Internet
Author: User
Tags php file php and

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 ();
?>
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.