note 54159 added to function.ob-start

From: Date: Sat, 25 Jun 2005 08:52:18 +0000
Subject: note 54159 added to function.ob-start
Groups: php.notes 
Request: Send a blank email to php-notes+get-90936@lists.php.net to get a copy of this message
I couldn't get the following code to work: <?php function ob_callback($buffer) { $buffer .= file_get_contents('template/footer.html'); return $buffer; } ?> After some fiddling I came up with this: <?php $footer_html = file_get_contents('template/footer.html'); function ob_callback($buffer) { global $footer_html; $buffer .= $footer_html; return $buffer; } ?> Not sure why file_get_contents() won't work inside the callback function, perhaps because of some silliness with the function writing directly to the buffer, even though it should be returning a string (which is does in other cases). Even more perplexing: <?php function ob_callback($buffer) { $buffer .= var_export(file_get_contents('template/footer.html'),true); return $buffer; } ?> Returns error: Fatal error: var_export(): Cannot use output buffering in output buffering display handlers in c:\pretend\pub_html\_tests\iwantmuscle\funcs.inc.php on line 920 So, it's also impossible for me to examine the return value of file_get_contents() in this case as well. Anyone have any ideas on this? (using 4.3.10 on Apache 1.3.27 offline development server). ---- Manual Page -- http://www.php.net/manual/en/function.ob-start.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+54159 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54159&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54159&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54159&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54159&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54159&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54159&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+54159&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#90936) next »