Introduction
When a 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 for sending http headers to the browser after the script has started outputting data. The output control function does not affect the file header information sent by header() or setcookie(), only the data between functions like echo and PHP code blocks.
Note:
Due to defects in earlier versions, when upgrading from PHP4.1.x (4.2.x, 4.3.x), you must ensure that implicit_flush in php.ini is OFF, otherwise any use of ob_start() The output 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 will be saved in the output buffer until ob_end_flush() is called. At the same time, the call to setcookie() also successfully stores a cookie without causing an error. (Under normal circumstances, after the data is sent to the browser, the http header information can no longer be sent.)
Output control function
flush — Flush the output buffer
ob_clean — Clear (erase) the output buffer
ob_end_clean — Clear (erase) the buffer and close the output buffer
ob_end_flush — Flush (send out) the contents of the output buffer and close the buffer
ob_flush — Flush (send) the contents of the output buffer
ob_get_clean — Get the current The contents of the buffer and delete the current output buffer.
ob_get_contents — Returns the contents of the output buffer
ob_get_flush — Flushes (sends out) the buffer contents, returns the 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 buffer mechanism
ob_get_status — Gets the status of all output buffers
ob_gzhandler — Used in ob_start to compress the output buffer Content callback function.
ob_implicit_flush — Turn on/off absolute flushing
ob_list_handlers — List all output handlers in use.
ob_start — Turn on the output control buffer
output_add_rewrite_var — Add URL rewriter values
output_reset_rewrite_vars — Reset URL rewriter values