Reputation: 324810
I am using output buffering to process stuff (very descriptive, I know).
What I'd like to do is cause output buffering to end, have the handler functions perform their processing, and then get the resulting output as a string, not output to the browser.
Is this possible? I can't seem to work out what combination of ob_end
/ob_get
functions I would need to achieve this... and my initial thought of "I can just buffer the output of ob_end_flush
" is... well, absurd :p
As a basic example of what I'm trying to achieve:
<?php
ob_start(function($c) {return "PASS\n";});
echo "FAIL\n";
$c = ob_get_contents();
ob_end_flush(); // outputs PASS, as it has been processed
echo $c; // outputs FAIL, because that was the content of the buffer... unprocessed...
// I want it processed.
Upvotes: 2
Views: 298
Reputation: 79024
I see the issue now with the edits and comments. You are correct that you'll need another output buffer since the callback is only called when flush or end is called and before any get in the function:
ob_start(function($c) {return "PASS\n";});
echo "FAIL\n";
ob_start();
ob_end_flush(); // buffers PASS, as it has been processed
$c = ob_get_contents();
echo $c; // outputs PASS
Upvotes: 1