Jump to content

Starting a buffer within a buffer callback function?


Jiokah

Recommended Posts

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?

Link to comment
Share on other sites

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();

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.