简体   繁体   中英

Running a Python script on a PHP server

I am running a nginx web server, along with PHP-CGI.

I would like to know if it is possible to execute a Python script inside PHP pages, allowing both languages to be combined. I've attempted it briefly but it didn't work, so I'm not sure how I would do this. Here are the two files I used:

index.php

<body>

    <p>Hello! Here is a message: <?php exec('python hello.py'); ?></p>

</body>

hello.py

print 'Hello World!'

Any clues would be appreciated.

exec will return the output of the shell command, but you still need to echo that to the page. The following code should work for you

<body>

    <p>Hello! Here is a message: <?php echo exec('python hello.py'); ?></p>

</body>

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