php 生成静态页面如何包含 头部及尾部的文件 ssi(服务器端包含)和js(客户端) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 具体如何包含在静态页面中不能用include 用window.write 输出我是把头尾用文件读进去以后然后再生成静态页面然而这样的话万一头部文件改动也就是说所有的生成的静态都需要调整了<head><meta http-equiv="Content-Type" content="text/html; charset=??????"><title>{title}</title></head><body>{head}<!--头部--><table width="500" border="1" align="center"> <tr> <td align="center"><strong>{title}</strong></td> </tr> <tr> <td>{content}</td> </tr> <tr> <td align="right">{datetime}</td> </tr></table>{end}}<!--尾部(include("end.htm"))--></html> $fp = fopen ("index.html","r"); $fileinfo= fread ($fp,filesize ("index.html")); $title="静态页面的生成"; $info="页面的内容"; $datetime=date("Y-m-d H:i:s"); $fp1 = fopen ("head.html","r");//生成头部 $head= fread ($fp1,filesize ("head.html")); fclose($fp1); $fp2 = fopen ("end.html","r"); $end= fread ($fp2,filesize ("end.html"));//生成尾部 fclose($fp2); $content = str_replace ("{head}",$head,$fileinfo);//输出头部 $content = str_replace ("{head}",$end,$fileinfo);//输出尾部 $content = str_replace ("{title}",$title,$fileinfo); $content = str_replace ("{content}",$info,$fileinfo); $content = str_replace ("{datetime}",$datetime,$fileinfo); $filename = "test/test.html"; $handle = fopen ($filename,"w"); //打开文件指针,创建文件 /* 检查文件是否被创建且可写 */ if (!is_writable ($filename)){ die ("文件:".$filename."不可写,请检查其属性后重试!"); } if (!fwrite ($handle,$content)){ //将信息写入文件 die ("生成文件".$filename."失败!"); } fclose ($handle); //关闭指针 die ("创建文件".$filename."成功!");fclose($fp) 如果部头尾做相应的修改 而这种方试就不可取了静态页面如果去包含一个页面 (就像include require 一样谢谢) iframe 属性连接一个页面就可以了 js 和 iframe 都可以实现,不过不利于搜索引擎收录。可以考虑用 shtml ,如:<!--#include virtual="/includes/header.html" -->去查查shtml ssi 相关的说明。 shtml吧,或者js都可以 建议shtml js的话搜索引荐会不找这些链接的! 关于openssl求大牛 php 链接的替换。 php正则表达式问题 .htaccess里如匹配问号 PHP中输出一张表格,能显示当前目录下所有文件的信息 问一个菜鸟问题 ajax的引用 关于imap应用 能否提供一个可以缩图,并且在缩图的上面打上字,并且输出到某个指定文件夹里面 imail邮件服务器的问题。通过php怎么在imail中加入邮件用户? 一个正则表达式的问题 急用~~谢谢 在线求助:在php中读取大文件(eg:csv)
在静态页面中不能用include
我是把头尾用文件读进去以后然后再生成静态页面
然而这样的话万一头部文件改动也就是说所有的生成的静态都需要调整了<head>
<meta http-equiv="Content-Type" content="text/html; charset=??????">
<title>{title}</title>
</head><body>
{head}<!--头部-->
<table width="500" border="1" align="center">
<tr>
<td align="center"><strong>{title}</strong></td>
</tr>
<tr>
<td>{content}</td>
</tr>
<tr>
<td align="right">{datetime}</td>
</tr>
</table>
{end}}<!--尾部(include("end.htm"))-->
</html>
$fileinfo= fread ($fp,filesize ("index.html"));
$title="静态页面的生成";
$info="页面的内容";
$datetime=date("Y-m-d H:i:s"); $fp1 = fopen ("head.html","r");//生成头部
$head= fread ($fp1,filesize ("head.html"));
fclose($fp1);
$fp2 = fopen ("end.html","r");
$end= fread ($fp2,filesize ("end.html"));//生成尾部
fclose($fp2); $content = str_replace ("{head}",$head,$fileinfo);//输出头部
$content = str_replace ("{head}",$end,$fileinfo);//输出尾部 $content = str_replace ("{title}",$title,$fileinfo);
$content = str_replace ("{content}",$info,$fileinfo);
$content = str_replace ("{datetime}",$datetime,$fileinfo);
$filename = "test/test.html";
$handle = fopen ($filename,"w"); //打开文件指针,创建文件
/*
检查文件是否被创建且可写
*/
if (!is_writable ($filename)){
die ("文件:".$filename."不可写,请检查其属性后重试!");
}
if (!fwrite ($handle,$content)){ //将信息写入文件
die ("生成文件".$filename."失败!");
}
fclose ($handle); //关闭指针
die ("创建文件".$filename."成功!");fclose($fp)
js的话搜索引荐会不找这些链接的!