Search code examples
phpoutput-buffering

strange ob_start() behaviour - double output


ob_start() doesn't seem to be stopping any output so when I flush the buffer it's doubling up

<?php
ob_start();
echo "Text..... <br />";
echo ob_get_flush();
?>

Outputs

Text..... 
Text..... 

But I was expecting

Text..... 

Any ideas ?

Thanks


Solution

  • Remove the echo on the last line.

    ob_get_flush() implicitly prints the stored output and also returns it so you're printing it out twice.

    You may have confused ob_get_flush() with ob_get_clean()