ob_end_clean

(PHP 4, PHP 5, PHP 7, PHP 8)

ob_end_cleanLimpiar (eliminar) el búfer de salida y deshabilitar el almacenamiento en el mismo

Descripción

ob_end_clean(): bool

Esta función desecha el contenido del búfer de salida en cola y lo desactiva. Si fuera necesario continuar procesando el contenido del búfer, se ha de llamar a ob_get_contents() antes que a ob_end_clean(), ya que el contenido del búfer es desechado cuando se llama a ob_end_clean().

El búfer de salida debe estar iniciado por ob_start() con los indicadores PHP_OUTPUT_HANDLER_CLEANABLE y PHP_OUTPUT_HANDLER_REMOVABLE. Si no, ob_end_clean() no funcionará.

Valores devueltos

Devuelve true en caso de éxito o false en caso de error. Entre las posibles razones de un fallo se encuentra llamar a la función sin un búfer activo, o que por algún motivo no se pueda eliminar un búfer (posible en el caso de búferes especiales).

Errores/Excepciones

Si la función falla, genera un error de nivel E_NOTICE.

Ejemplos

El siguiente ejemplo muestra una forma sencilla de deshacerse de todos los búferes de salida:

Ejemplo #1 Ejemplo de ob_end_clean()

<?php
ob_start
();
echo
'Texto que no será mostrado.';
ob_end_clean();
?>

Ver también

add a note

User Contributed Notes 2 notes

up
8
Sam Yong - hellclanner at live dot com
13 years ago
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.
up
7
John Smith
20 years ago
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
"";
}
...
}
?>
To Top