php生成静态HTML页面

发布时间:2021-07-16 17:15:36 阅读:1191次

 index.php

<body style="font-size:12px;">
<?php
 header("content-type:text/html;charset=utf-8");
 date_default_timezone_set("Asia/Shanghai");
 $cn=mysql_connect("localhost","root","123456");
 $db=mysql_select_db("dedecms");
 $sql="select * from dede_addonarticle,dede_archives where dede_addonarticle.aid=dede_archives.id and dede_addonarticle.aid=4";
 mysql_query("set names utf8");
 $result=mysql_query($sql);
 if($row=mysql_fetch_array($result)){
  $title=$row["title"];
  $body=$row["body"];
  $datetime=$row["senddate"];
  //echo $body;
  //echo date("y-m-d h:i:s",$datetime);
  $filename=date("y",$datetime).date("m",$datetime).date("d",$datetime).date("h",$datetime).date("i",$datetime).date("s",$datetime).".html";
  //echo $filename;
 }
 $file=fopen("template.html","r");
 //echo str_replace("the","THE",$str);
 //echo date("y-m-d H:i:s",fileatime("createtextfile.php"));  //返回文件的上次访问时间
 //print_r(file("createtextfile.php"));
 $webtitle=str_replace("#webtitle#",$title."--".$filename,file_get_contents("template.html"));
 $title=str_replace("#title#",$title,$webtitle);
 $content=str_replace("#content#",$body,$title);
 $fso=fopen($filename,"w");
 fwrite($fso,$content);
 echo "静态页面已经成功生成,"."<a href=".$filename.">请查看</a>"
?>
</body>
</html>

template.html

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>
 #webtitle#
</title>
</head>
<style type=text/css>
.title{
 font-weight:bold;
 color:#FF0000;
 font-size:14px;
 font-family:arial;
 text-align:center;
}
.content{
 text-indent:45px;
 font-size:12px;
 color:#000000;
 font-family:arial;
}
</style>
<body>
<div class="title">#title#</div>
<br/>
<span class="content">
#content#
</span>
</body>
</html>

如有问题,可以QQ搜索群1028468525加入群聊,欢迎一起研究技术

支付宝 微信

有疑问联系站长,请联系QQ:QQ咨询
上一篇: MySQL Index详解
下一篇:php操作xml

转载请注明:php生成静态HTML页面 出自老鄢博客 | 欢迎分享