Is there a way to write Python in PHP?
过去多啦不再A梦
过去多啦不再A梦 2017-05-16 13:00:21
0
3
461

Is there a PHP implementation of Python?

过去多啦不再A梦
过去多啦不再A梦

reply all(3)
Peter_Zhu

You can call shell commands in phppythonExecute python files

伊谢尔伦

The respondent’s question is not clear enough.

Do you want:

  1. Run Python files through PHP? That's no different than applying ordinary shell commands.

  2. Requires interaction between PHP and Python, such as applying a certain function or class of Python in PHP.

  3. Requires a Python parser written in PHP.

PHPzhong

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template