0

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!

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Is there any way to "include" the script? Or the only way to do it is to exec the script?
The only way is to exec the script. Trying to include it would cause PHP to try to parse it as PHP, which wont work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.