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:

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:

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

especially useful when implementing templates with PHP.