简体   繁体   中英

Include python script/program in PHP

I am new to Python and currently have to write a python program/script to be integrated inside PHP. Basically I have one stand-alone python program that will be executed through CRONTAB that grabs data from a remote device and exports the data to an XML file. I also have to write another python program/script to be include inside PHP to read the XML and echo/print the data onto the screen. So my question is that

  1. What is the difference between python program and script? Given my python program, I included #!/usr/bin/env python at the beginning of the file but I still cant execute it using ./scriptName.py

  2. How to include and run a python program/script inside the PHP file? Inside the python script, how to output the data using the same manner as echo in PHP? The include part in my PHP is:

     <td><p><img src="img/today.gif" alt="today" width="180" height="40" /></p> <?php include "monthphotos.php"; ?> <?php include "todayatcpp/index.php"; ?> </td> 

I am new to beginner programmer so some of my questions can be obscure. Sorry!

The only way you can run a python script inside of a PHP script is to use the exec call. With that you will be able to capture the output from the python script and be able to use it in PHP.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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