PHP buffering output example analysis, PHP buffering example analysis_PHP tutorial

WBOY
Release: 2016-07-13 10:10:16
Original
771 people have browsed it

php buffer output instance analysis, php buffering instance analysis

The example in this article describes the usage of php buffered output. Share it with everyone for your reference. The specific analysis is as follows:

ob_start([string output_callback]) - Open the output buffer

All output information is no longer sent directly to the browser, but is saved in the output buffer. An optional callback function is used to process the output result information.

ob_end_flush - End (send) the contents of the output buffer, close the output buffer

The example code is as follows:

Copy code The code is as follows:
ob_start(); //Open the buffer
echo "hello world"; //Output content
$out=ob_get_clean(); //Get the buffer content and end the buffer
$out=strtolower($out); //Convert characters to lowercase
var_dump($out); //Output result
//

if(!function_exists('ob_clean')) //Determine whether the function is defined
{
function ob_clean() //Define function
{
If(@ob_end_clean())
{
Return ob_start();
}
​ trigger_error("ob_clean() failed to delete buffer.no buffer to delete.",e_user_notice);
Return false;
}
}
//

header('content-type: multipart/x-mixed-replace;boundary=endofsection'); //Send header
print "n--endofsectionn"; //Output content
$pmt=array("-","","|","/"); //Define array
for($i=0;$i<10;$i++) //Operation through loop
{
sleep(1); //Pause execution
Print "content-type: text/plainnn"; //Output content
Print "part $it".$pmt[$i % 4]; //Output content
Print "--endofsectionn"; //Output content
ob_flush(); //Send buffer data
flush(); //Refresh the output buffer
}
print "content-type: text/plainnn"; //Output content
print "the endn"; //Output content
print "--endofsection--n"; //Output content

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/937724.htmlTechArticlephp buffer output example analysis, php buffer output example analysis This article describes the usage of php buffer output. Share it with everyone for your reference. The specific analysis is as follows: ob_start([string output_ca...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template