PHP Output Buffering Control

Source: Internet
Author: User
Tags setcookie

Brief introduction

When the PHP script has output, the output control function can use these to control the output. This is useful in a number of different situations, especially when the script begins to output data and sends an HTTP header message to the browser. The output control function does not affect the header information sent by the header () or Setcookie (), only affects functions such as echo and the data between PHP blocks.

Attention:

Due to the previous version of the defect, when upgrading from php4.1.x (4.2.x,4.3.x), you must ensure that the Implicit_flush in php.ini is off, otherwise any output with Ob_start () will be hidden in the output.

Basic usage

<?php    Ob_start ();    echo "hello\n";    Setcookie ("CookieName", "Cookiedata");    Ob_end_flush ();? >

In the above example, the output of the Echo function is kept in the output buffer until Ob_end_flush () is called. Also, the call to Setcookie () successfully stores a cookie without causing an error. (Normally, after the data is sent to the browser, it is no longer possible to send HTTP header information.) )

Output control function

flush-Refresh Output buffering

ob_clean-Empty (erase) the output buffer

ob_end_clean-Empty (Erase) buffer and turn off output buffering

ob_end_flush-flushes out (sends out) the output buffer content and turns off buffering

ob_flush-Flushing out (sending out) the contents of the output buffer

Ob_get_clean-gets the contents of the current buffer and deletes the current output ease.

ob_get_contents-returns the contents of the output buffer

ob_get_flush-brushes out (sends out) buffer content, returns content as a string, and closes the output buffer.

ob_get_length-returns the length of the output buffer content

ob_get_level-returns the nesting level of the output buffering mechanism

ob_get_status-get the status of all output buffers

Ob_gzhandler-the callback function used in Ob_start to compress the contents of the output buffer.

ob_implicit_flush-turn on/off absolute swipe

ob_list_handlers-lists all the output handlers in use.

ob_start-Open Output Control buffer

output_add_rewrite_var-Add the value of the URL rewrite (add URL rewriter values)

output_reset_rewrite_vars-resetting the value of the URL rewrite (reset URL rewriter values)

  • Related Article

    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.