如何使用 WampServer 在 HTML 文件中包含 PHP 脚本?

How to include PHP script in HTML file with WampServer?

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

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

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

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

当我 运行 :index.html: 作为本地主机在 WampServer 上时,来自 "index.html: is displayed. How do I display "Hello world! 的 PHP 代码来自 "footer.php"?

谢谢!

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

I have an HTML script ("index.html") which includes the follow PHP code:

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

希望这会有所帮助

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

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

我认为 < 和 index.php 中的 ? 之间的 space 造成了问题。

编辑: index.php 中 <? 之间的确切 space 正在产生问题并打印 php 代码。

左键单击计算机右下方托盘中的 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>