【问题标题】:How can I run an php code inside html (test.html) file?如何在 html (test.html) 文件中运行 php 代码?
【发布时间】:2016-07-20 16:45:05
【问题描述】:

如何在 HTML 中显示 PHP 代码?如果这可以通过使用 .htaccess 文件来完成,

  1. 我可以在本地服务器(如 wamp)上使用它吗?
  2. 谁能为此任务提供一个示例 .htaccess 文件?

【问题讨论】:

    标签: php html .htaccess


    【解决方案1】:

    您可以使用任何您想要的扩展来运行 PHP。使用 Apache,您只需将以下内容添加到您的 .htaccess

    Addhandler application/x-httpd-php .html .php .whatever
    

    【讨论】:

    • 我可以在本地服务器 (wamp) 中运行此代码吗? PHP 版本 - 5.5.12 和 Apache 版本 - 2.4.9
    【解决方案2】:

    您不能在以 .html 结尾的 html 页面中运行 php 但除非页面是 PHP 并且扩展名已使用 .htaccess 从 .php 更改为 .html

    并在 .htaccess 文件中使用它

    RewriteEngine on
    RewriteRule ^(.*)\.html$ $1.php [nc]
    

    阅读更多How to hide extension PHP, HTML, HTM with .htaccess

    【讨论】:

      猜你喜欢
      • 2018-08-12
      • 2019-06-27
      • 1970-01-01
      • 2012-12-10
      • 1970-01-01
      • 2020-12-31
      • 2020-07-02
      • 2017-09-20
      • 2012-08-30
      相关资源
      最近更新 更多