Is there a PHP implementation of Python?
You can call shell commands in phppythonExecute python files
python
The respondent’s question is not clear enough.
Do you want:
Run Python files through PHP? That's no different than applying ordinary shell commands.
Requires interaction between PHP and Python, such as applying a certain function or class of Python in PHP.
Requires a Python parser written in PHP.
import sys
def do_some(a):return "dosome:%s" % a
if name == '__main__':a = sys.argv[1]if a:T = do_some(a)print T
//t.php
<?php$k = $_REQUEST['k'];if (!empty($k)){$k = trim($k);// $a = array(); // exec('python ./some.py '.$k, $a);// echo $a[0];passthru('python ./some.py '.$k);}
In my example above, py and php are placed in the same directory
Then enter http://localhost/t.php?k=test in the browserThe browser will return dosome:test
But you must have a python environment
You can call shell commands in php
python
Execute python filesThe respondent’s question is not clear enough.
Do you want:
Run Python files through PHP? That's no different than applying ordinary shell commands.
Requires interaction between PHP and Python, such as applying a certain function or class of Python in PHP.
Requires a Python parser written in PHP.
some.py
!/usr/bin/env python
-- coding:utf-8 --
import sys
def do_some(a):
return "dosome:%s" % a
if name == '__main__':
a = sys.argv[1]
if a:
T = do_some(a)
print T
//t.php
<?php
$k = $_REQUEST['k'];
if (!empty($k))
{
$k = trim($k);
// $a = array();
// exec('python ./some.py '.$k, $a);
// echo $a[0];
passthru('python ./some.py '.$k);
}
In my example above, py and php are placed in the same directory
Then enter http://localhost/t.php?k=test in the browser
The browser will return dosome:test
But you must have a python environment