欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PHP生成靜態(tài)HTML文檔實現(xiàn)代碼

 更新時間:2016年06月23日 09:15:19   作者:2778085001  
這篇文章主要為大家詳細(xì)介紹了PHP生成靜態(tài)HTML文檔實現(xiàn)代碼,將數(shù)據(jù)庫中的文章數(shù)據(jù)生成單個的HTML文檔原理,感興趣的小伙伴們可以參考一下

利用PHP,將數(shù)據(jù)庫中的文章數(shù)據(jù)生成單個的HTML文檔。首先,有利于搜索引擎的收錄。其次,避免數(shù)據(jù)庫中的字段暴露在地址欄上,更安全。
給出代碼:

<?php
//引入數(shù)據(jù)庫配置文件
include( dirname(dirname(__FILE__))."\include\config.php" );

/**
 * 
 * 將數(shù)據(jù)庫中的文章生成單個HTML文件.
 * @param Date $Date
 * @param Time $Time
 * @param String $Content
 * @param String $Title
 */
function GenerateHTML($Date,$Time,$Content,$Title,$Name){

//將日期、時間變量分解成數(shù)組
$GetDateRow = explode("-", $Date);
$GetTimeRow = explode(":",$Time);

//得到文件的名字。比如:20121028210632.html
$FileName = $GetDateRow[0].$GetDateRow[1].$GetDateRow[2].$GetTimeRow[0].$GetTimeRow[1].$GetTimeRow[2].".html";

//打開并讀取模板內(nèi)容
$FP = fopen("tmp.html","r");
$Str = fread($FP,filesize("tmp.html"));

//得到替換后的模板內(nèi)容
$Str = str_replace("{Title}",$Title, $Str);
$Str = str_replace("{Content}", $Content, $Str);
$Str = str_replace("{Name}", $Name, $Str);
$Str = str_replace("{Date}", $Date,$Str);
$Str = str_replace("{Time}", $Time, $Str);

//關(guān)閉文件,減少服務(wù)器的壓力。
fclose($FP);

//將內(nèi)容寫入HTML文件
$Handle = fopen($FileName,"w");
fwrite($Handle,$Str);
fclose($Handle);

//小測一下
//echo "ok,done!";

}

//數(shù)據(jù)庫的操作
$querysql = "select * from article";
$queryset = mysql_query($querysql);

//循環(huán)生成HTML文件。
while( $row = mysql_fetch_array($queryset) ){
  GenerateHTML($row['date'],$row['time'],$row['content'],$row['title'],$row['name']);
}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論