Is there a PHP implementation of Python?
伊谢尔伦2017-05-16 13:02:21
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.
PHPz2017-05-16 13:02:21
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