I am currently screwing around with php and python. I've made a simple python script which is literally just - print "Hello World"
My php script (which is inside my index.php main page) is as follows:
<?php
$output = null;
exec('C:\\Python27\\python.exe py\\test.py', $output, $return);
print_r($output);
?>
My problem is that it returns this:
Array ( [0] => Hello World )
Does anyone know how to only return Hello World
into my webpage? Any help would be greatly appreciated.
The simplest way is to replace print_r($output) with echo $output[0].
But as the exec-Statement returns an array with every line, it only works with a single-line return-value from the python-script. If you really want the whole output, you have to loop through the array.
When specifying an output variable, it would fill it with an array of every line of output.
Instead, save the actual result of the exec function to a variable, and echo that.
if (is_array($output)){
foreach($output as $v) echo $v . "<br>";}
else echo $output