Jiokah Posted December 2, 2007 Share Posted December 2, 2007 Hi guys, I have a little problem. I'm trying to start an output buffer within the callback function of another buffer, but it doesn't seem to work. Was wondering if anyone knows why. Here's a (very) stripped down snippet of my code: function ob_callback() { return some_function(); } function some_function() { return ob_start() ? "true" : "false"; ob_end_clean(); } ob_start("ob_callback"); ob_end_flush(); Neither "true" nor "false" is returned, though if I had typed "return 'hello'", the output would of been "hello". Basically what I'm trying to do is capture the (processed) output of a PHP file into a variable within the ob callback function. Does anyone know how I can do this without starting another buffer if it turns out this is impossible? Quote Link to comment https://forums.phpfreaks.com/topic/79798-starting-a-buffer-within-a-buffer-callback-function/ Share on other sites More sharing options...
lur Posted December 2, 2007 Share Posted December 2, 2007 function ob_callback($buffer) { $buffer; // holds buffer } ob_start('ob_callback'); // ... ob_end_flush(); Quote Link to comment https://forums.phpfreaks.com/topic/79798-starting-a-buffer-within-a-buffer-callback-function/#findComment-404093 Share on other sites More sharing options...
Jiokah Posted December 2, 2007 Author Share Posted December 2, 2007 Hey thanks for the reply, but (excuse my ignorance), what do you mean by your code there? Quote Link to comment https://forums.phpfreaks.com/topic/79798-starting-a-buffer-within-a-buffer-callback-function/#findComment-404126 Share on other sites More sharing options...
lur Posted December 2, 2007 Share Posted December 2, 2007 function ob_callback($buffer) { ob_start(); // Fatal error: ob_start(): Cannot use output buffering in output buffering display handlers } ob_start('ob_callback'); ob_end_flush(); function _flush() { $buffer = ob_get_clean(); ob_start(); require 'foo.php'; echo $buffer . ob_get_clean(); flush(); } ob_start(); echo date('r'); _flush(); Quote Link to comment https://forums.phpfreaks.com/topic/79798-starting-a-buffer-within-a-buffer-callback-function/#findComment-404271 Share on other sites More sharing options...
Jiokah Posted December 4, 2007 Author Share Posted December 4, 2007 Oh smart idea, this is a perfect solution, thanks a lot! Quote Link to comment https://forums.phpfreaks.com/topic/79798-starting-a-buffer-within-a-buffer-callback-function/#findComment-406212 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.