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.
ob_clean
(PHP 4 >= 4.2.0, PHP 5)
ob_clean — 出力バッファをクリア(消去)する
説明
void ob_clean ( void )この関数は、出力バッファの内容を破棄します。
この関数は、ob_end_clean()のように出力バッファ を破棄しません。
ob_flush(), ob_end_flush(), ob_end_clean()も参照ください。
ob_clean
cipri at php dot net
30-Jun-2004 01:54
30-Jun-2004 01:54
kouber at php dot net
11-May-2004 09:05
11-May-2004 09: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 01: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().