基础问题在php中可以使用include ("head.html")吗?

xujian2009 2010-07-26 06:48:42
本人刚学习php,属于菜鸟,希望能够得到帮助。我想把我网页头部head和foot,都做成单独的页面,然后在index.php页面中包含就head和foot。使用include ("head.html");语句可以吗?如果不行,有什么好的建议吗?
...全文
748 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
xujian2009 2010-07-26
  • 打赏
  • 举报
回复
[Quote=引用 16 楼 amani11 的回复:]
服了

既然文件名是.html

<?php
include("head.php");//文件名总要一致吧?????
?>

如果是纯粹的html文件,,在这个html文件里,就没必要<?php ?>等格式

如果是需要解析的php文件,最好保存为.php吧
[/Quote]

谢谢啊,我也发现了,太粗心。
amani11 2010-07-26
  • 打赏
  • 举报
回复
服了

既然文件名是.html

<?php
include("head.php");//文件名总要一致吧?????
?>

如果是纯粹的html文件,,在这个html文件里,就没必要<?php ?>等格式

如果是需要解析的php文件,最好保存为.php吧
CodeBus 2010-07-26
  • 打赏
  • 举报
回复
不管是什么后缀名的文件,php都可以include进来,其中的<?php ?>部分会被解析。其他的部分保持原来的样子输出。。
LuciferStar 2010-07-26
  • 打赏
  • 举报
回复
如果include "*.*",是把*.*里的数据插入到当前程序。
如果*.*是PHP脚本,会被解析,如果不是,则原文显示。
xujian2009 2010-07-26
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 amani11 的回复:]
麻烦,代码格式,,贴出html文件内容看看
[/Quote]

好的,谢谢,我已经在11楼贴出来了,麻烦您看看。
xujian2009 2010-07-26
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 matezy 的回复:]
在PHP里可以indclude('head.html');
但不能从html里include('head.php');
[/Quote]

可以吗?你实现了?
xujian2009 2010-07-26
  • 打赏
  • 举报
回复
head.html代码

<?php
<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title></title>

<link rel="stylesheet" type="text/css" href="/computer/css/index.css" />

<script type="text/javascript" src="/computer/lib/jquery.js"></script>
<script language="javascript" src="/computer/lib/trimpath.js"></script>


</head>

<body>
<div class="index_container">

<div class="index_head_container">

<div class="index_head_image_container">
<a href="/computer/index.html"><img src="/computer/images/logo.gif"></img></a>
</div>

<div class="index_head_content_container">

<ul>
<li id="index_content_showtime"></li>
<li>推荐分辨率1024 × 768</li>
</ul>

</div>

</div>

<!--隐藏的top信息数据模板层-->
<div id="index_template_info_top_container" style="display:none">

<embed class="index_head_flash" pluginspage="http://www.macromedia.com/go/getflashplayer" src="/computer/flash/${info.top_flash}" type="application/x-shockwave-flash" wmode="transparent" quality="high"></embed>

</div>

<!--top信息目标输出层-->
<div id="index_top_flash_container"></div>

</div>

</body>

</html>
?>
<script src="/computer/javascript/head.js"></script>

index.php代码

<?php
include("head.php");
?>

但是head.html中内容不能显示出来啊?
matezy 2010-07-26
  • 打赏
  • 举报
回复
在PHP里可以indclude('head.html');
但不能从html里include('head.php');
amani11 2010-07-26
  • 打赏
  • 举报
回复
麻烦,代码格式,,贴出html文件内容看看
xujian2009 2010-07-26
  • 打赏
  • 举报
回复
我加上这就话了,AddType application/x-httpd-php 后面加上 .html
可是还是在php页面不能显示html中的内容啊。
amani11 2010-07-26
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 piger920 的回复:]

引用 4 楼 cunningboy 的回复:
你这样,不会影响html正常的解析?

他说的是把html当作php解析 和lz的问题没有关系 不解析也是可以include的
[/Quote]

貌似不影响解析的

AddType application/x-httpd-php 后面加上 .html

这样做的目的是,,,如果有人访问file.html,不至于把代码泄露
PIGer920 2010-07-26
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 cunningboy 的回复:]
你这样,不会影响html正常的解析?
[/Quote]
他说的是把html当作php解析 和lz的问题没有关系 不解析也是可以include的
PIGer920 2010-07-26
  • 打赏
  • 举报
回复
可以的。。。
CunningBoy 2010-07-26
  • 打赏
  • 举报
回复
你这样,不会影响html正常的解析?
amani11 2010-07-26
  • 打赏
  • 举报
回复
何不试试?呢。。。

这是可以的

如果.html里,有php代码,请在apache的配置文件里
AddType application/x-httpd-php 后面加上 .html

意思就是.html后缀的,作为php文件来解析。
CunningBoy 2010-07-26
  • 打赏
  • 举报
回复
不可以,只能include php文件,但是你可以将head.html头部添加<?php ?>空语句,然后将文件保存为php文件。
ja11082 2010-07-26
  • 打赏
  • 举报
回复
抢沙发!

21,890

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧