php将数据库中所有内容生成静态html文档的代码_PHP
程序员文章站
2022-05-26 15:04:37
...
复制代码 代码如下:
/*
author:www.5dkx.com
done:生成html文档
date:2009-10-27
*/
require_once("conn.php");
if($_GET['all'])
{
/*获取数据库记录,以便于生成html文件有个文件名*/
$sqlquery = "select * from $tbname";
$result = mysql_query($sqlquery,$conn)or die("查询失败!");
$fp = fopen("./template/article.html",r);
$fpcontent = fread($fp,filesize("./template/article.html"));
fclose($fp);
/*写入文件*/
while($row = mysql_fetch_array($result))
{
$fpcontent = str_replace("{thetitle}",$row['title'],$fpcontent);
$fpcontent = str_replace("{chatitle}",$row['title'],$fpcontent);
$fpcontent = str_replace("{bookcontent}",$row['content'],$fpcontent);
$fp = fopen("./html/".$row['id'].".html",w)or die("打开写入文件失败!");
fwrite($fp,$fpcontent)or die("写入文件失败!");
}
echo "";
}
if($_GET['part'])
{
/*获取最后一条记录的ID,以便于生成html文件有个文件名*/
$sqlquery = "select * from $tbname order by id desc limit 1";
$result = mysql_query($sqlquery,$conn)or die("查询失败!");
$row = mysql_fetch_array($result);
$fp = fopen("./template/article.html",r);
$fpcontent = fread($fp,filesize("./template/article.html"));
fclose($fp);
$fpcontent = str_replace("{thetitle}",$row['title'],$fpcontent);
$fpcontent = str_replace("{chatitle}",$row['title'],$fpcontent);
$fpcontent = str_replace("{bookcontent}",$row['content'],$fpcontent);
$fp = fopen("./html/".$row['id'].".html",w)or die("打开写入文件失败!");
fwrite($fp,$fpcontent)or die("写入文件失败!");
echo "";
}
?>
生成html文档
echo "全部更新
部分更新";
?>
/*
author:www.5dkx.com
done:生成html文档
date:2009-10-27
*/
require_once("conn.php");
if($_GET['all'])
{
/*获取数据库记录,以便于生成html文件有个文件名*/
$sqlquery = "select * from $tbname";
$result = mysql_query($sqlquery,$conn)or die("查询失败!");
$fp = fopen("./template/article.html",r);
$fpcontent = fread($fp,filesize("./template/article.html"));
fclose($fp);
/*写入文件*/
while($row = mysql_fetch_array($result))
{
$fpcontent = str_replace("{thetitle}",$row['title'],$fpcontent);
$fpcontent = str_replace("{chatitle}",$row['title'],$fpcontent);
$fpcontent = str_replace("{bookcontent}",$row['content'],$fpcontent);
$fp = fopen("./html/".$row['id'].".html",w)or die("打开写入文件失败!");
fwrite($fp,$fpcontent)or die("写入文件失败!");
}
echo "";
}
if($_GET['part'])
{
/*获取最后一条记录的ID,以便于生成html文件有个文件名*/
$sqlquery = "select * from $tbname order by id desc limit 1";
$result = mysql_query($sqlquery,$conn)or die("查询失败!");
$row = mysql_fetch_array($result);
$fp = fopen("./template/article.html",r);
$fpcontent = fread($fp,filesize("./template/article.html"));
fclose($fp);
$fpcontent = str_replace("{thetitle}",$row['title'],$fpcontent);
$fpcontent = str_replace("{chatitle}",$row['title'],$fpcontent);
$fpcontent = str_replace("{bookcontent}",$row['content'],$fpcontent);
$fp = fopen("./html/".$row['id'].".html",w)or die("打开写入文件失败!");
fwrite($fp,$fpcontent)or die("写入文件失败!");
echo "";
}
?>
echo "全部更新
部分更新";
?>
上一篇: nginx cache 配置
下一篇: php连接mssql的一些相关经验和总结