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?

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.