PHP provides a group of functions to control the output. Here, the output is the content that is sent to the browser by the script.

Note: The functions listed on this page control the output using the buffers. Some output controlling functions create multiple buffers placed over each other. Any output of the upper buffer is caught by the buffer beneath. These output functions can only handle the topmost buffer. In order to control the underlying buffers, the topmost buffer must be removed.

Possible output sources from the PHP script can be the following.

  • Statements like echo, print_r, print_f, and print.
  • Warning, errors, or notices from PHP.
  • Content out of PHP starting /closing tags (<? PHP ?>).

In some cases, PHP uses buffers to store the output before sending it to the browser.

flush()Send content from the system’s output buffer to the browser
ob_clean()Delete all of the content from the topmost output buffer
ob_end_clean()Deletes the topmost output buffer and all of its contents
ob_end_flush()Deletes the topmost output buffer and outputs its contents
ob_flush()Output the contents of the topmost output buffer and clears the buffer
ob_get_clean()Returns all of the contents of the topmost output buffer and clears the buffer
ob_get_contents()Returns the contents of the topmost output buffer
ob_get_flush()Output and Get the contents of the topmost output buffer and then Remove the buffer
ob_get_length()Returns the number of bytes of data that are in the topmost output buffer
ob_get_level()Returns a number indicating how many output buffers are on the stack
ob_get_status()Returns information about the output buffers
ob_gzhandler()Used as a callback function for ob_start() to compress the contents of the buffer when sending it to the browser
ob_implicit_flush()Turns implicit flushing on or off
ob_list_handlers()Returns an array of callback function names that are being used by the topmost output buffer
ob_start()Create a new output buffer and adds it to the top of the stack
output_add_rewrite_var()Used to append query string parameters to any URL in the output
output_reset_rewrite_vars()Remove all variables added by output_add_rewrite_var()
Output functions in PHP