In order to read the direct output of a PHP script into a variable for later processing
it needs to be buffered.

a buffer can be started with:
ob_start();

then anything that would output data directly can be executed, for example:
include 'foo.php' ; ( which might contain something like: echo 'bar' ; )

then read the buffer into a variable:
$buffer= ob_get_contents();

and clean the buffer afterwards:
ob_end_clean();

That’s it. Now whatever foo.php was outputting is now stored in
$buffer for further processing.

especially useful when implementing templates with PHP.