Analysis of php buffer output instances

Source: Internet
Author: User
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.

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.