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

yipeiwu_com6年前PHP代码库
复制代码 代码如下:

<?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}",$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 "<script language=\"javascript\">alert('全部更新');</script>";
}
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 "<script language=\"javascript\">alert('部分更新成功!');</script>";
}
?>
<html>
<head>
<title>生成html文档</title>
<script language="javascript">
function btnsubmit(form)
{
theform.submit();
}
</script>
</head>
<body>
<?
echo "<a href=?all=111>全部更新</a><br><a href=?part=111>部分更新</a>";
?>
</body>
</html>

相关文章

php简单隔行变色功能实现代码 原创

本文简单分析了php简单隔行变色功能实现方法。分享给大家公大家参考。具体如下: $color=""; echo "隔行变色效果:"; echo "<ul>"; for($...

基于empty函数的输出详解

$a = '';echo '1.---------------'.empty($a).'<br>';$a = '0';echo '2.---------------'.emp...

php常用Output和ptions/Info函数集介绍

flush函数:刷新输出缓冲ob_clean函数:清空输出缓冲ob_end_clean函数:清空缓冲区并且关闭正在进行的输出缓冲ob_end_flush函数:发送缓冲区数据并且关闭缓冲区...

学习php设计模式 php实现策略模式(strategy)

学习php设计模式 php实现策略模式(strategy)

一、意图 定义一系列的算法,把它们一个个封装起来,并且使它们可相互替换。策略模式可以使算法可独立于使用它的客户而变化 策略模式变化的是算法 二、策略模式结构图   三、策略模式...

PHP实现的数据对象映射模式详解

PHP实现的数据对象映射模式详解

本文实例讲述了PHP实现的数据对象映射模式。分享给大家供大家参考,具体如下: 还是代码说话:这里还是遵循策略模式的psr-0代码规范 数据表: 数据库连接文件Db.php(如果没有可...