PHP Output Control Functions

About This Index
This page is the PHP Output Control Functions index for the tutorial track. Each row links to a full guide with syntax, examples, and FAQs.
Learn why buffering exists, how to capture with ob_get_clean(), flush() versus ob_flush(), and nested levels on /php/output-control. Use this page when you need a specific function such as ob_start(), ob_get_clean(), or flush().
Start with ob_start() and ob_get_clean()—then learn ob_flush() versus flush(), and finish with ob_get_level() for nested buffers.
Every Output Control function in this series appears below in four categories: start & inspect, send & clear, handlers & flush helpers, and URL rewrite vars.
How to Call a PHP Output Control Function
Output Control helpers are global functions—call them directly. Start a buffer, write output, then capture, send, or discard:
ob_start();
echo 'buffered text';
$copy = ob_get_contents(); // string|false
$len = ob_get_length(); // int|false
$lvl = ob_get_level(); // int
$text = ob_get_clean(); // capture + end
ob_start();
echo 'chunk';
ob_flush(); // send, keep buffering
flush(); // system write buffers
ob_end_clean(); // discard + end
$handlers = ob_list_handlers(); // array of names PHP Output Control Functions Table
All function guides in this PHP tutorial series (17 tutorials in 4 categories).
Start & inspect
6 functionsTurn buffering on, copy buffer contents, and inspect length, nesting level, status, and active handlers.
| Function | Description | Tutorial |
|---|---|---|
ob_start() | Turn on output buffering; optional callback filters each flush. | Try it |
ob_get_contents() | Return the contents of the active buffer without ending it. | Try it |
ob_get_length() | Return the length of the active output buffer. | Try it |
ob_get_level() | Return how many nested output buffers are active. | Try it |
ob_get_status() | Return status information about the active buffer (or all levels). | Try it |
ob_list_handlers() | List the names of the active output handlers. | Try it |
Send & clear
6 functionsSend buffer contents to the next layer, erase draft output, or capture text and end the buffer in one step.
| Function | Description | Tutorial |
|---|---|---|
ob_clean() | Erase the active buffer contents and keep buffering on. | Try it |
ob_end_clean() | Erase the active buffer and turn that level off. | Try it |
ob_flush() | Send (flush) the active buffer and keep buffering on. | Try it |
ob_end_flush() | Send the active buffer and turn that level off. | Try it |
ob_get_clean() | Get the buffer contents and turn that level off. | Try it |
ob_get_flush() | Get the buffer contents, flush them, and turn that level off. | Try it |
Handlers & flush helpers
3 functionsPush system write buffers, use the gzip output callback, or enable implicit flush after output.
| Function | Description | Tutorial |
|---|---|---|
flush() | Flush system write buffers (does not empty an ob_start buffer). | Try it |
ob_gzhandler() | Gzip callback used with ob_start() to compress buffered output. | Try it |
ob_implicit_flush() | Turn implicit flushing on or off so output may flush automatically. | Try it |
URL rewrite vars
2 functionsRegister or clear name/value pairs used when PHP rewrites URLs and forms in buffered output.
| Function | Description | Tutorial |
|---|---|---|
output_add_rewrite_var() | Add a name/value pair for URL and form rewriting. | Try it |
output_reset_rewrite_vars() | Reset all rewrite variables previously added. | Try it |
Frequently Asked Questions
Start with flush()
Open the next guide—syntax, examples, and FAQs.
7 people found this page helpful
