PHP Include for HTML?(用于 HTML 的 PHP 包含?)
问题描述
I have a navigational bar, an image, and a heading that I'll be including in every page of my website, so I wanted to use php include to refer to this code in several pages. However, I think I may have the syntax wrong or something because it's not rendering anything when I load it. Here are some code snippets:
<!-- sample page --> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
<?php include ('headings.php'); ?>
</head>
<body>
<?php include ('navbar.php'); ?>
<?php include ('image.php'); ?>
</body>
</html>
navbar.php
<?php
echo '<ul id="nav">
<li>
<a href="Home.html">Home</a>
</li>
<li>
<a>About Me</a>
<ul>
<li>
<a href="Career.html">Career</a>
</li>
<li>
<a href="Coding.html">Coding</a>
</li>
<li>
<a href="Personal.html">Personal</a>
</li>
</ul>
</li>
<li>
<a href="Travels.html">Travel</a>
</li>
<li>
<a href="Contact.html">Contact</a>
</li>
</ul>';
?>
Thanks for helping!
You can use php
code in files with extension .php
and only there (iff other is not defined in your server settings).
Just rename your file *.html
to *.php
If you want to allow php
code processing in files of different format, you have two options to do that:
1) Modifying httpd.conf
to allow this for all projects on your server, by adding:
AddHandler application/x-httpd-php .htm .html
2) Creating .htaccess
file in your separate project top directory with:
<Files />
AddType application/x-httpd-php .html
</Files>
For second option you need to allow use of .htaccess
files in your httpd.conf
, by adding the following settings:
AllowOverride All
AccessFileName .htaccess
*that is correct for Apache HTTP Server
这篇关于用于 HTML 的 PHP 包含?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:用于 HTML 的 PHP 包含?


- Laravel 仓库 2022-01-01
- 从 PHP 中的输入表单获取日期 2022-01-01
- PHP Count 布尔数组中真值的数量 2021-01-01
- SoapClient 设置自定义 HTTP Header 2021-01-01
- 没有作曲家的 PSR4 自动加载 2022-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- Mod使用GET变量将子域重写为PHP 2021-01-01
- 正确分离 PHP 中的逻辑/样式 2021-01-01
- 如何定位 php.ini 文件 (xampp) 2022-01-01
- 带有通配符的 Laravel 验证器 2021-01-01