[Tutor] PHP & Python suggestions....

Alan Gauld alan.gauld at btinternet.com
Mon Feb 4 06:23:28 CET 2008


"GTXY20" <gtxy20 at gmail.com> wrote

> Anyway, I am looking for some suggestions for reading up on how to 
> call
> Python from PHP scripts, specifically calling from a PHP web 
> application -
> PHP will call python script with some arguments and python will run 
> on the
> server and return the results within another PHP page.

Since PHP is also running on the server then the equivalent of
os.system in Python should work. The equivalent of os.popen
would p[robably be even better, although tyou could use an
output file to exchange data. My (very old) PHP book says:

passthru can be used to put the outoput on the web page or using
back ticks you can capture the output in a variable.

So

$myvar = `python myscript.py`

would store the output of the Python command as a string in $myvar

HTH,

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 




More information about the Tutor mailing list