複製代碼 代碼如下:
/*
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 "全部更新
部分更新";
?>
http://www.bkjia.com/PHPjc/321556.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/321556.htmlTechArticle複製代碼 代碼如下: ?php /* author:www.5dkx.com done:產生html文檔 date:2009-10-27 */ require_once("conn.php"); if($_GET['all']) { /*擷取資料庫記錄,以便於產生...