php生成静态HTML页面

 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>

    A+
发布日期:2021年07月16日  所属分类:未分类

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: