How to solve ob_start ();

Source: Internet
Author: User
About ob_start (); would you like to ask: ob_start (); ob_get_contents (); ob_end_clean (); what are the specific functions and when they are used, review the new function introduction of PHP4 in the response from the November 03-output information control function magic genie about ob_start ();
Want to ask: ob_start (); ob_get_contents (); ob_end_clean ();
What are the specific use cases of these three functions?

------ Solution --------------------
Revised the answer from the agency for the past 03

Introduction to new functions of PHP4-output information control functions
Magic Genie


These functions allow you to control the content output by your script. it can be used in many different situations, especially when your script has output information, you need to send a new file header. the output control function does not affect the header information sent using header () or setcookie (). it only applies to data blocks similar to echo () and PHP code.

Example 1. control output


Ob_start ();
Echo "Hello \ n ";

Setcookie ("cookiename", "cookiedata ");

Ob_end_flush ();

?>

In the preceding example, the output content using echo () is saved in the output buffer until ob_end_flush () is called (). it makes sense that the content that calls setcookie () is successfully stored in the cookie without causing errors. (normally, you cannot send the file header information to your browser after the data has been sent .)

Related function header () and setcookie ().

Korea list
Flush-refresh the output buffer
The content stored in the output buffer is sent to the browser.

Ob_start-open the output buffer
In this way, all output information is not directly sent to the browser, but saved in the output buffer.

Ob_get_contents-return the content of the output buffer
If you want to process the output content in the future, you can call this function to keep a backup.

Ob_get_length-return the content length of the output buffer

Ob_end_flush-end (SEND) output buffer content, disable the output buffer

Ob_end_clean-delete (discard) the output buffer and disable the output buffer.
If your program finds a problem with the output content, you can discard all output content to prevent leakage of some confidential information.

Ob_implicit_flush-refresh directly when it is enabled or disabled
After the script is opened, the output of each script is directly sent to the browser, and you do not need to call flush (),

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.