For example, in foo.php:
<?php echo 'hello'; ?>
And in bar.php, I want to get the output of foo.php (which is hello) and do some formatting before outputting to browser. Is there any way to do this?
Or even further, if the webserver can run both PHP and Python scripts, can a PHP script get the output of a Python script?
Edit:
PHP function file_get_contents() can do this only for remote scripts. If it is used on local scripts, it will return the contents of the whole script. In the example above, it returns rather than hello. And I don’t want to use exec()/system() things and CGI.
You can use PHP’s output buffers and functions like ob_start(); and ob_get_contents(); to read the contents of your PHP output into a string.
Here is the example on php.net:
And another: