ob_end_clean
(PHP 4, PHP 5)
ob_end_clean — Clean (erase) the output buffer and turn off output buffering
Description
This function discards the contents of the topmost output buffer and turns off this output buffering. If you want to further process the buffer's contents you have to call ob_get_contents() before ob_end_clean() as the buffer contents are discarded when ob_end_clean() is called.
Return Values
Returns TRUE
on success or FALSE
on failure. Reasons for failure are first that you called the
function without an active buffer or that for some reason a buffer could
not be deleted (possible for special buffer).
Errors/Exceptions
If the function fails it generates an E_NOTICE
.
Changelog
Version | Description |
---|---|
4.2.0 | The boolean return value was added. |
Examples
The following example shows an easy way to get rid of all output buffers:
Example #1 ob_end_clean() example
<?php
ob_start();
echo 'Text that won\'t get displayed.';
ob_end_clean();
?>
See Also
- ob_start() - Turn on output buffering
- ob_get_contents() - Return the contents of the output buffer
- ob_flush() - Flush (send) the output buffer
Коментарии
Note that if you started called ob_start with a callback, that callback will still be called even if you discard the OB with ob_end_clean.
Because there is no way of removing the callback from the OB once you've set it, the only way to stop the callback function from having any effect is to do something like:
<?php
$ignore_callback = false;
ob_start('my_callback');
...
if($need_to_abort) {
$ignore_callback = true;
ob_end_clean();
...
}
function my_callback(&$buffer) {
if($GLOBALS['ignore_callback']) {
return "";
}
...
}
?>
Take note that if you change zlib output compression setting in between ob_start and ob_end_clean or ob_end_flush, you will get an error: ob_end_flush() failed to delete buffer zlib output compression
Example:
<?php
ob_start();
$output = ob_get_contents();
ini_set('zlib.output_compression', '1');
ob_end_clean();
?>
ob_end_clean(); in this example will throw the error.