use PHP to generate a single HTML document for the article data in the database. First, to facilitate the inclusion of search engines. Second, it is more secure to avoid exposing fields in the database to the Address bar.
give the code:
Php//introducing a database configuration fileinclude(dirname(dirname(__file__))." \include\config.php " );/** * * generate a single HTML file for the articles in the database. * @param Date $Date * @param time $Time * @param string $Content * @param string $Title
*/functionGeneratehtml ($Date,$Time,$Content,$Title,$Name){//decompose date and time variables into groups$GetDateRow=Explode("-",$Date);$GetTimeRow=Explode(":",$Time);//get the name of the file. For example: 20121028210632.html$FileName=$GetDateRow[0].$GetDateRow[1].$GetDateRow[2].$GetTimeRow[0].$GetTimeRow[1].$GetTimeRow[2]. ". html;//open and Read template content$FP=fopen("Tmp.html", "R");$Str=fread($FP,filesize("Tmp.html"));//get the template content after replacement$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);//close the file and reduce the pressure on the server. fclose($FP);//writing content to an HTML file$Handle=fopen($FileName, "W");fwrite($Handle,$Str);fclose($Handle);//Small test//echo "ok,done!";}//operation of the database$querysql= "SELECT * FROM article";$queryset=mysql_query($querysql);//loops through the generation of HTML files. while($row=Mysql_fetch_array($queryset) {generatehtml ($row[' Date '],$row[' Time '],$row[' content '],$row[' title '],$row[' Name ']);}
ok,done!
The above describes the pseudo-static HTML using PHP to generate static HTML documents, including the pseudo-static HTML content, I hope to be interested in PHP tutorial friends helpful.