php將資料庫中所有內容產生靜態html文檔的代碼

來源:互聯網
上載者:User

複製代碼 代碼如下:<?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>
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.