8.13.1 Problem
8.13.2 Solution
Call ob_start( ) at the top of
your page and ob_end_flush( ) at the bottom. You
can then intermix commands that generate output and commands that send headers.
The output won't be sent until ob_end_flush( ) is called:
<?php ob_start(); ?>
I haven't decided if I want to send a cookie yet.
<?php setcookie('heron','great blue'); ?>
Yes, sending that cookie was the right decision.
<?php ob_end_flush(); ?>
8.13.3 Discussion
You can pass ob_start( ) the name of a callback function to process the output buffer
with that function. This is useful for postprocessing all the content in a page,
such as hiding email addresses from address-harvesting
robots:
<?php
function mangle_email($s) {
return preg_replace('/([^@\s]+)@([-a-z0-9]+\.)+[a-z]{2,}/is',
'<$1@...>',
$s);
}
ob_start('mangle_email');
?>
I would not like spam sent to ronald@example.com!
<?php ob_end_flush(); ?>
I would not like spam sent to <ronald@...>!
output_buffering = On
output_handler=mangle_email
Setting an output_handler automatically sets
output_buffering to on.