栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > PHP

利用PHP生成静态HTML文档的原理

PHP 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

利用PHP生成静态HTML文档的原理

给出代码:
复制代码 代码如下:
//引入数据库配置文件
include( dirname(dirname(__FILE__))."includeconfig.php" );


function GenerateHTML($Date,$Time,$Content,$Title,$Name){

//将日期、时间变量分解成数组
$GetDateRow = explode("-", $Date);
$GetTimeRow = explode(":",$Time);

//得到文件的名字。比如:20121028210632.html
$FileName = $GetDateRow[0].$GetDateRow[1].$GetDateRow[2].$GetTimeRow[0].$GetTimeRow[1].$GetTimeRow[2].".html";

//打开并读取模板内容
$FP = fopen("tmp.html","r");
$Str = fread($FP,filesize("tmp.html"));

//得到替换后的模板内容
$Str = str_replace("{Title}",$Title, $Str);
$Str = str_replace("{Content}", $Content, $Str);
$Str = str_replace("{Name}", $Name, $Str);
$Str = str_replace("{Date}", $Date,$Str);
$Str = str_replace("{Time}", $Time, $Str);

//关闭文件,减少服务器的压力。
fclose($FP);

//将内容写入HTML文件
$Handle = fopen($FileName,"w");
fwrite($Handle,$Str);
fclose($Handle);

//小测一下
//echo "ok,done!";

}

//数据库的操作
$querysql = "select * from article";
$queryset = mysql_query($querysql);

//循环生成HTML文件。
while( $row = mysql_fetch_array($queryset) ){
GenerateHTML($row['date'],$row['time'],$row['content'],$row['title'],$row['name']);
}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/50451.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号