PHP Function Reference

PHP ob_get_flush() Function



The PHP ob_get_flush() function flushes the output buffer, return it as a string and turns off output buffering. This function is similar to ob_end_flush(), except that this function also returns the buffer as a string.

Note: The output buffer must be started by ob_start() with PHP_OUTPUT_HANDLER_FLUSHABLE flag. Otherwise this function will not work.

Syntax

ob_get_flush()

Parameters

No parameter is required.

Return Value

Returns the output buffer or false if no buffering is active.

Example: ob_get_flush() example

The example below shows the usage of ob_get_flush() function.

<?php
//adding first output buffer
ob_start();
echo "Content of first output buffer.\n";

//adding second output buffer
ob_start();
echo "Content of second output buffer.\n";

//adding third output buffer
ob_start();
echo "Content of third output buffer.\n";

//clearing the content of topmost output buffer
//(third output buffer) and turns it off
ob_end_clean();

//flushing and closing rest of the output buffers
while(ob_get_level() != 0) {
  ob_get_flush();
}
?>

The output of the above code will be:

Content of first output buffer.
Content of second output buffer.

❮ PHP Output Control Reference