PHP Function Reference

PHP ob_end_flush() Function



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

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

Syntax

ob_end_flush()

Parameters

No parameter is required.

Return Value

Returns true on success or false on failure.

Example: ob_end_flush() example

The example below shows the usage of ob_end_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_end_flush();
}
?>

The output of the above code will be:

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

❮ PHP Output Control Reference