php将数据库中所有内容生成静态html文档的代码

前端之家收集整理的这篇文章主要介绍了php将数据库中所有内容生成静态html文档的代码前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

<div class="codetitle"><a style="CURSOR: pointer" data="16923" class="copybut" id="copybut16923" onclick="doCopy('code16923')"> 代码如下:

<div class="codebody" id="code16923">
<?PHP
/
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}",$fpcontent);
$fpcontent = str_replace("{bookcontent}",$row['content'],$fpcontent);
$fp = fopen("./html/".$row['id'].".html",w)or die("打开写入文件失败!");
fwrite($fp,$fpcontent)or die("写入文件失败!");
}
echo "<script language=\"javascript\">alert('全部更新');";
}
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",filesize("./template/article.html"));
fclose($fp);
$fpcontent = str_replace("{thetitle}",$fpcontent)or die("写入文件失败!");
echo "<script language=\"javascript\">alert('部分更新成功!');";
}
?>


<a href="https://www.jb51.cc/tag/shengcheng/" target="_blank" class="keywords">生成</a>html文档
<script language="javascript">
function btnsubmit(form)
{
theform.submit();
}



<?
echo "<a href=?all=111>全部更新
<a href=?part=111>部分更新";
?>


原文链接:https://www.f2er.com/php/28651.html

猜你在找的PHP相关文章