[ACCEPTED]-How do I include a PHP script in Python?-execution
import subprocess def php(script_path): p = subprocess.Popen(['php', script_path], stdout=subprocess.PIPE) result = p.communicate() return result # YOUR CODE BELOW: page_html = "<h1>News and Updates</h1>" news_script_output = php("news-generator.php") print page_html + news_script_output
PHP is a program. You can run any program 2 with subprocess.
The hard part is simulating the whole 1 CGI environment that PHP expects.
maybe off topic, but if you want to do this 8 in a way where you can access the vars and 7 such created by the php script (eg. array 6 of news items), your best best will be to 5 do the exec of the php script, but return 4 a json encoded array of items from php as 3 a string, then json decode them on the python 2 side, and do your html generation and iteration 1 there.
There is an open-source widget 2 thing that will run multiple languages in 1 1 page but I cant remember what its called.
You could use urllib to get the page from 4 the server (localhost) and execute it in 3 the right environment for php. Not pretty, but 2 it'll work. It may cause performance problems 1 if you do it a lot.
More Related questions