ob_start();
$phpinfo = phpinfo();
//Write to file
ob_end_flush();
Or there is such a use:
ob_start(); //Open buffer
echo "Hellon"; //Output
header("location:index.php"); //Redirect the browser to index.php
ob_end_flush();//Output all content to the browser
Header() will send a file header to the browser, but if there is any output before header() (including empty output, such as spaces, carriage returns and line feeds), an error will be reported. But if the output is between ob_start() and ob_end_flush(), there will be no problem. Because the buffer is opened before output, the characters after echo will not be output to the browser, but will be retained on the server. They will not be output until flush is used, so header() will execute normally.
Of course, ob_start() can also have parameters, and the parameter is a callback function. Examples are as follows:
The code is as follows
|
Copy code
|
< ?php<🎜>
function callback($buffer)<🎜>
{<🎜>
// replace all the apples with oranges<🎜>
return (str_replace("apples", "oranges", $buffer));<🎜>
}<🎜>
ob_start("callback");<🎜>
?>
< html >
< body >
It's like comparing apples to oranges.
< / body >
< / html >
< ?php<🎜>
ob_end_flush();<🎜>
?>
The above program will output:
< html >
< body >
< p>It's like comparing oranges to oranges. p>
< / body >
< / html >
For more information, just go to the manual on the official website.
http://www.bkjia.com/PHPjc/632725.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632725.htmlTechArticlePage caching is to save the page to a file, and call the file directly the next time it is read without querying the database. Here we introduce the use of ob_start() to achieve it. Example code is as follows Copy code...
|
|