Ob_start()
It opens a buffer where the output is
stored.
Every time you do an
echo, the output is added to that buffer.
When you call ob_flush() the
output is sent to the browser.
function callback($buffer) {
return str_replace("apples", "bananas", $buffer);
}
ob_start("callback");
?>
My string with apples and oranges.
<?php
ob_end_flush();
You have
more control over the output.
ob_start();
$header = "UnitTests - %s <hr>";
echo "My tests passed ... <br>";
$passed = true;
echo "My tests 2 failed ... <br>";
$passed = false;
$output = ob_get_contents();
ob_end_clean();
$header = sprintf($header, $passed ? "Passed" : "Failed");
echo $header . $output;