Output Control Functions Output Control The Output Control functions allow you to control when output is sent from the script. This can be useful in several different situations, especially if you need to send headers to the browser after your script has began outputting data. The Output Control functions do not affect headers sent using header or setcookie, only functions such as echo and data between blocks of PHP code. Output Control example ]]> In the above example, the output from echo would be stored in the output buffer until ob_end_flush was called. In the mean time, the call to setcookie successfully stored a cookie without causing an error. (You can not normally send headers to the browser after data has already been sent.) See also header and setcookie. flush Flush the output buffer Description voidflush Flushes the output buffers of PHP and whatever backend PHP is using (CGI, a web server, etc). This effectively tries to push all the output so far to the user's browser. flush has no effect on the buffering scheme of your webserver or the browser on the client side. Several servers, especially on Win32, will still buffer the output from your script until it terminates before transmitting the results to the browser. Server modules for Apache like mod_gzip may do buffering of their own that will cause flush to not result in data being sent immediately to the client. Even the browser may buffer its input before displaying it. Netscape, for example, buffers text until it receives an end-of-line or the beginning of a tag, and it won't render tables until the </table> tag of the outermost table is seen. Some versions of Microsoft Internet Explorer will only start to display the page after they have received 256 bytes of output, so you may need to send extra whitespace before flushing to get those browsers to display the page. ob_start Turn on output buffering Description voidob_start string output_callback This function will turn output buffering on. While output buffering is active no output is sent from the script (other than headers), instead the output is stored in an internal buffer. The contents of this internal buffer may be copied into a string variable using ob_get_contents. To output what is stored in the internal buffer, use ob_end_flush. Alternatively, ob_end_clean will silently discard the buffer contents. An optional output_callback function may be specified. This function takes a string as a parameter and should return a string. The function will be called when ob_end_flush is called, or when the output buffer is flushed to the browser at the end of the request. When output_callback is called, it will receive the contents of the output buffer as its parameter and is expected to return a new output buffer as a result, which will be sent to the browser. In PHP 4.0.4, ob_gzhandler was introduced to facilitate sending gz-encoded data to web browsers that support compressed web pages. ob_gzhandler determines what type of content encoding the browser will accept and will return it's output accordingly. Output buffers are stackable, that is, you may call ob_start while another ob_start is active. Just make sure that you call ob_end_flush the appropriate number of times. If multiple output callback functions are active, output is being filtered sequentially through each of them in nesting order. ob_end_clean, ob_end_flush, ob_clean, ob_flush and ob_start may not be called from a callback function. If you call them from callback function, the behavior is undefined. If you would like to delete the contents of a buffer, return "" (a null string) from callback function. User defined callback function example

It's like comparing apples to oranges. ]]> Would produce:

It's like comparing oranges to oranges. ]]> See also ob_get_contents, ob_end_flush, ob_end_clean, ob_implicit_flush and ob_gzhandler. ob_get_contents Return the contents of the output buffer Description stringob_get_contents This will return the contents of the output buffer or &false;, if output buffering isn't active. See also ob_start and ob_get_length. ob_get_length Return the length of the output buffer Description stringob_get_length This will return the length of the contents in the output buffer or &false;, if output buffering isn't active. See also ob_start and ob_get_contents. ob_get_level Return the nesting level of the output buffering mechanism Description intob_get_level This will return the level of nested output buffering handlers. See also ob_start and ob_get_contents. ob_gzhandler ob_start callback function to gzip output buffer Description stringob_gzhandler stringbuffer intmode mode was added in PHP 4.0.5. ob_gzhandler is intended to be used as a callback function for ob_start to help facilitate sending gz-encoded data to web browsers that support compressed web pages. Before ob_gzhandler actually sends compressed data, it determines what type of content encoding the browser will accept ("gzip", "deflate" or none at all) and will return it's output accordingly. All browsers are supported since it's up to the browser to send the correct header saying that it accepts compressed web pages. <function>ob_gzhandler</function> Example

This should be a compressed page. ]]> See also ob_start and ob_end_flush. ob_flush Flush (send) the output buffer Description voidob_flush This function will send the contents of the output buffer (if any). If you want to further process the buffer's contents you have to call ob_get_contents before ob_flush as the buffer contents are discarded after ob_flush is called. This function does not destroy the output buffer like ob_end_flush does. See also ob_get_contents, ob_clean, ob_end_flush and ob_end_clean. ob_clean Clean (erase) the output buffer Description voidob_clean This function discards the contents of the output buffer. This function does not destroy the output buffer like ob_end_clean does. See also ob_flush, ob_end_flush and ob_end_clean. ob_end_flush Flush (send) the output buffer and turn off output buffering Description voidob_end_flush This function will send the contents of the output buffer (if any) and turn output buffering off. If you want to further process the buffer's contents you have to call ob_get_contents before ob_end_flush as the buffer contents are discarded after ob_end_flush is called. See also ob_start, ob_get_contents, ob_flush and ob_end_clean. ob_end_clean Clean (erase) the output buffer and turn off output buffering Description voidob_end_clean This function discards the contents of the output buffer and turns off output buffering. See also ob_start, ob_clean and ob_end_flush. ob_implicit_flush Turn implicit flush on/off Description voidob_implicit_flush intflag ob_implicit_flush will turn implicit flushing on or off (if no flag is given, it defaults to on). Implicit flushing will result in a flush operation after every output call, so that explicit calls to flush will no longer be needed. Turning implicit flushing on will disable output buffering, the output buffers current output will be sent as if ob_end_flush had been called. See also flush, ob_start, and ob_end_flush.