It is relatively simple, and my code optimization is also very complicated. The following code is used directly.
The code is as follows:
/*
Author: www.5dkx.com
Done: generate html documents
Date: 2009-10-27
*/
Require_once ("conn. php ");
If ($ _ GET ['all'])
{
/* Obtain database records to generate html files with a file name */
$ Sqlquery = "select * from $ tbname ";
$ Result = mysql_query ($ sqlquery, $ conn) or die ("query failed! ");
$ Fp = fopen ("./template/article.html", r );
$ Fpcontent = fread ($ fp, filesize ("./template/article.html "));
Fclose ($ fp );
/* Write file */
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 ("Opening and writing files failed! ");
Fwrite ($ fp, $ fpcontent) or die ("failed to write file! ");
}
Echo"