Use PHP to generate a single HTML document from the article data in the database. First of all, it is beneficial to search engine inclusion. Secondly, it is safer to avoid exposing fields in the database to the address bar.
Give code:
<?php //引入数据库配置文件 include( dirname(dirname(__FILE__))."\include\config.php" ); /** * * 将数据库中的文章生成单个HTML文件. * @param Date $Date * @param Time $Time * @param String $Content * @param String $Title */ function GenerateHTML($Date,$Time,$Content,$Title,$Name){ //将日期、时间变量分解成数组 $GetDateRow = explode("-", $Date); $GetTimeRow = explode(":",$Time); //得到文件的名字。比如:20121028210632.html $FileName = $GetDateRow[0].$GetDateRow[1].$GetDateRow[2].$GetTimeRow[0].$GetTimeRow[1].$GetTimeRow[2].".html"; //打开并读取模板内容 $FP = fopen("tmp.html","r"); $Str = fread($FP,filesize("tmp.html")); //得到替换后的模板内容 $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); //关闭文件,减少服务器的压力。 fclose($FP); //将内容写入HTML文件 $Handle = fopen($FileName,"w"); fwrite($Handle,$Str); fclose($Handle); //小测一下 //echo "ok,done!"; } //数据库的操作 $querysql = "select * from article"; $queryset = mysql_query($querysql); //循环生成HTML文件。 while( $row = mysql_fetch_array($queryset) ){ GenerateHTML($row['date'],$row['time'],$row['content'],$row['title'],$row['name']); }
The above is the entire content of this article. I hope it will be helpful to everyone’s study. I also hope that everyone will support Bangke Home.
in the database