How do I include a PHP script in Python?

后端 未结 5 2224
暗喜
暗喜 2021-02-09 05:56

I have a PHP script (news-generator.php) which, when I include it, grabs a bunch of news items and prints them. Right now, I\'m using Python for my website (CGI). When I was usi

5条回答
  •  遥遥无期
    2021-02-09 06:03

    import subprocess
    
    def php(script_path):
        p = subprocess.Popen(['php', script_path], stdout=subprocess.PIPE)
        result = p.communicate()[0]
        return result
    
    # YOUR CODE BELOW:
    page_html = "

    News and Updates

    " news_script_output = php("news-generator.php") print page_html + news_script_output

提交回复
热议问题