note 22797 added to function.ob-start

From: Date: Sun, 30 Jun 2002 15:42:39 +0000
Subject: note 22797 added to function.ob-start
Groups: php.notes 
Request: Send a blank email to php-notes+get-32438@lists.php.net to get a copy of this message
Remember that you *cannot* output anything directly from within the output_callback function. This code, for example: <?php function callback() { echo "Output buffering is over, but this also won't be displayed."; } ob_start('callback'); echo 'This will never be displayed.'; ob_end_clean(); ?> Will show no output whatsoever, as output buffering is still in place when the callback function is called. Using ob_end_flush instead of ob_end_clean doesn't appear to help. Everything you want to output from the function must be returned, not printed, like so: <?php function callback() { return 'Output buffering is over, and this will actually be displayed.'; } ob_start('callback'); echo 'This will never be displayed.'; ob_end_clean(); ?> My tests have also shown that you don't *have* to take the current output buffer as a parameter in the callback function. -- http://www.php.net/manual/en/function.ob-start.php http://master.php.net/manage/user-notes.php?action=edit+22797 http://master.php.net/manage/user-notes.php?action=delete+22797 http://master.php.net/manage/user-notes.php?action=reject+22797

« previous php.notes (#32438) next »