ob_clean

(PHP 4 >= 4.2.0, PHP 5)

ob_clean --  Clean (erase) the output buffer

Description

void ob_clean ( void )

This function discards the contents of the output buffer.

This function does not destroy the output buffer like ob_end_clean() does.

See also ob_flush(), ob_end_flush() and ob_end_clean().


add a note add a note User Contributed Notes
cipri at php dot net
30-Jun-2004 12:54
In Re: to Anonymous at 14-Jan-2003.

You can't mimic the behaviour 100% by using that combination of function calls(ob_end_clean() && ob_start()), since outputhandlers may be defined already by the initial ob_start, which may not work as expected when called twice.
kouber at php dot net
11-May-2004 08:05
Although it is mentioned in the manual, you have to be careful when using output buffering in big cycles (such as mass mail sending scripts), because ob_clean() actually does not free any memory, and with each iteration the amount of memory allocated from your script will increase significantly. Instead of calling ob_clean() at the end of the cycle, you have to either use ob_get_clean(), which is a combination of ob_get_contents() and ob_end_clean(), or just ob_end_clean() to free the memory. Try the following test to see the difference:

<?php
for ($i=0; $i<10; $i++) {
 
ob_start();

  echo
"This is iteration $i: ";

 
// * Don't do this!
  // $buf = ob_get_contents();
  // ob_clean();

  // * Use this instead:
 
$buf = ob_get_clean();

  echo
$buf;
 
  echo
memory_get_usage()."\n";
}
?>
15-Jan-2003 12:23
As far as I can tell the only way to mimic ob_clean()'s behaviour on PHP < 4.2.0 is calling ob_end_clean() followed by ob_start().