This article mainly introduces the usage of php buffer output and provides a complete analysis of the buffer output implementation process in the form of instances, which has some reference value, for more information about php buffer output, see the following example. Share it with you for your reference. The specific analysis is as follows:
Ob_start ([string output_callback])-open the output buffer
All output information is not directly sent to the browser, but saved in the output buffer. the optional callback function is used to process output result information.
Ob_end_flush-end (SEND) output buffer content, disable the output buffer
The instance code is as follows:
The code is as follows:
Ob_start (); // open the buffer
Echo "hello world"; // Output Content
$ Out = ob_get_clean (); // Obtain the buffer content and end the buffer.
$ Out = strtolower ($ out); // converts a character to lowercase.
Var_dump ($ out); // output result
//
If (! Function_exists ('OB _ clean') // checks whether the function is defined.
{
Function ob_clean () // define a 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 the header
Print "n -- endofsectionn"; // Output Content
$ Pmt = array ("-", "", "|", "/"); // defines an array
For ($ I = 0; $ I <10; $ I ++) // perform operations through loops
{
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 (); // sends the 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 help you with php programming.