简体   繁体   English

如何从python中获取价值并使用php在网页中显示

[英]how to get value from python and show in webpage using php

I have a PHP file called display.php and a python file giveDATA.py.我有一个名为 display.php 的 PHP 文件和一个 python 文件 giveDATA.py。

from giveDATA.py, this is output: (77, '8088800000')来自giveDATA.py,这是输出:(77, '8088800000')

I would like to capture this output in separate variables in PHP and print one by one on a webpage.我想在 PHP 中的单独变量中捕获此输出并在网页上一一打印。

1) display.php 1) 显示.php

<html>
<body>
<?php
    $command = escapeshellcmd('C:/guna/python/giveDATA.py');
    $x = shell_exec($command);
    echo "<pre>$x</pre>";
?>
</body>
</html>

2) giveDATA.py 2) 给DATA.py
In my python file I am getting values from a table:在我的 python 文件中,我从表中获取值:

    results=cursor.fetchall()

            for x in results:
                print(x)
            connection.commit()

The shell does not know that you want to run a script because you`re just giving it a path. shell 不知道你想运行一个脚本,因为你只是给它一个路径。 Replace this:替换这个:

$command = escapeshellcmd('C:/guna/python/giveDATA.py');

With this:有了这个:

$command = escapeshellcmd('python3 C:/guna/python/giveDATA.py');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM