问题描述
我有一个导航栏,一个图像和一个标题,我将在我的网站的每个页面中都包含这个标题,所以我想用php include来在几个页面中引用此代码。但是,我认为我可能有语法错误或者是因为它在我加载时没有呈现任何内容。以下是一些代码片段:
<! - 示例页面 - > <!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>主页< / a>
< / li>
< li>
< a>关于我< / a>
< ul>
< li>
< a href =Career.html>职业< / a>
< / li>
< li>
< a href =Coding.html>编码< / a>
< / li>
< li>
< a href =Personal.html>个人< / a>
< / li>
< / ul>
< / li>
< li>
< a href =Travels.html>旅游< / a>
< / li>
< li>
< a href =Contact.html>联络人< / a>
< / li>
< / ul>';
?>
感谢您的帮助!
您可以在扩展名为 .php
的文件中使用 php
其他未在您的服务器设置中定义)。
只需将您的文件 *。html
重命名为 *。php
如果你想允许 php
在不同格式的文件中处理代码,你有两个选择:
$ b 1)修改 httpd.conf
允许你的服务器上的所有项目都可以这样做:
AddHandler application / x-httpd -php .htm .html
创建 .htaccess
< Files /> $文件放置在您单独的项目顶部目录中:
AddType应用程序/ x-httpd-php .html
< / Files>
第二个选项需要允许使用
中的$ c>文件,并添加以下设置: .htaccess
httpd.conf
AllowOverride All
AccessFileName .htaccess
*对于Apache HTTP Server正确
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
这篇关于PHP包括HTML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!