【问题标题】:How to include PHP script in HTML file with WampServer?如何使用 WampServer 在 HTML 文件中包含 PHP 脚本?
【发布时间】:2017-07-08 08:11:33
【问题描述】:

我有一个 HTML 脚本(“index.html”),其中包含以下 PHP 代码:

< ?php
include ('footer.php');
?>

PHP 脚本(“footer.php”)包含以下代码:

<?php
   echo "Hello world!";
?>

当我在 WampServer 上作为 localhost 运行 :index.html: 时,会显示来自“index.html:”的 PHP 代码。如何显示来自“footer.php”的“Hello world!”?

谢谢!

【问题讨论】:

标签: php html localhost wamp wampserver


【解决方案1】:

我有一个 HTML 脚本(“index.html”),其中包含以下 PHP 代码:

这是错误的。您的 index.html 不会理解 PHP 代码。将您的 html 代码 index.html 重命名为 index.php

希望这会有所帮助

【讨论】:

  • 我重命名了我的 html 代码 index.php,它仍在打印 php 代码而不是“Hello world!”。
【解决方案2】:

我假设您将要包含的 php 文件作为 footer.php 保存在 index.php 所在的同一目录中。 现在您要在其中包含 footer.php,在所需位置包含此代码。

<?php
    include ('footer.php');
?>

我认为 index.php 中 ? 之间的空格造成了问题。

编辑: index.php 中 ? 之间的确切空间会产生问题并打印 php 代码。

【讨论】:

    【解决方案3】:

    要包含其他 php 脚本,您的索引页面应该使用 php 扩展名 (index.php) 而不是 index.html

    【讨论】:

      【解决方案4】:

      左键单击计算机右下角托盘中的 Wamp 图标 >> Apache >> 左键单击 httpd.conf >> 向下滚动 2/3 >> 添加 AddType application/x-httpd- php .html 如下图>>保存并关闭>>重启Wamp>>完成!

      <IfModule mime_module>
          AddType application/x-compress .Z
          AddType application/x-gzip .gz .tgz
          AddType application/x-httpd-php .php
          AddType application/x-httpd-php .php3
          AddType application/x-httpd-php .html
      </IfModule>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-07-24
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多