对于 php include,包含 include 的文件是否需要扩展名 .php?
For a php include does the file that contains the include need the extension .php?
我一直在努力学习如何为 html 网站制作 php 包含。我一直这样做的方式是在 php 文档中输入页眉、导航栏和页脚的代码,然后输入:
<?php
include("header.php")
?>
<?php
include("navbar.php")
?>
在html文件中我希望包含那些文件(about.html)等等。即使在使用 MAMP 进行测试时,这对我也不起作用。有一个更好的方法吗?我听说包含 include 的文件的文件扩展名需要是 php。感谢您的建议!
This has not been working for me even when testing with MAMP. Is there a better way to do this?
您可以通过在 header.php
和 footer.php
中回显 HTML 代码来包含它。直接将 .html
文件重命名为 .php
将不起作用。
I have heard that the file extension for the file that contains the include needs to be php.
您的文件必须是 PHP,否则您不能 include
。但是,您可以使用 .htaccess
指示系统将 .html
个文件视为 .php
个文件。 (感谢@Fred -ii- 指出)
我一直在努力学习如何为 html 网站制作 php 包含。我一直这样做的方式是在 php 文档中输入页眉、导航栏和页脚的代码,然后输入:
<?php
include("header.php")
?>
<?php
include("navbar.php")
?>
在html文件中我希望包含那些文件(about.html)等等。即使在使用 MAMP 进行测试时,这对我也不起作用。有一个更好的方法吗?我听说包含 include 的文件的文件扩展名需要是 php。感谢您的建议!
This has not been working for me even when testing with MAMP. Is there a better way to do this?
您可以通过在 header.php
和 footer.php
中回显 HTML 代码来包含它。直接将 .html
文件重命名为 .php
将不起作用。
I have heard that the file extension for the file that contains the include needs to be php.
您的文件必须是 PHP,否则您不能 include
。但是,您可以使用 .htaccess
指示系统将 .html
个文件视为 .php
个文件。 (感谢@Fred -ii- 指出)