> ...
ob_start(); // start trapping output
include "foo.php"; // produce output
$output = ob_getcontents(); // get contents of trapped output
ob_end_clean(); // discard trapped output and stop trapping
...
Exactly this is what I did so far before I realized, that the output buffer
is limited in size to 'output_buffering' in the php configuration, which is
set to 4096 bytes by default, but 4K is just not enough for me. I need it do
be unlimited. This could be done with 'output_buffering = On', which limits
the buffer to the RAM size for the script offered in 'memory_limit' (8M by
default).
PS: It must be done this way to make sure everything in the buffer before is
reinsert afterwards.
$old=ob_get_contents(); ob_clean(); ob_start(); // you may leave ob_start();
include ...;
$out=ob_get_contents(); ob_clean();
echo $old;