- Require_once ("conn.php");
- if ($_get[' all ')
- {
- /* Get database records so that the generated HTML file has 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 (" Open write file failed! ");
- Fwrite ($FP, $fpcontent) or Die ("Write file failed!");
- }
- echo "";
- }
- if ($_get[' part ')
- {
- /* Gets the ID of the last record, making it easy to generate an HTML file with a filename */
- $sqlquery = "SELECT * from $tbname the ORDER by id DESC limit 1";
- $result = mysql_query ($sqlquery, $conn) or Die ("Query failed!");
- $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 (" Open write file failed! ");
- Fwrite ($FP, $fpcontent) or Die ("Write file failed!");
- echo "";
- }
- ?>
- Generate HTML
- echo "All updates
Partial Update ";
- ?>
Copy Codeyou may be interested in the article:three ways to generate static pages in PHP and the code in detail PHP generates static page functions (php2html) example PHP method for generating static pages (three functions) The template of PHP generated static files and cache PHP write a static page generated on the class virtual host on a regular basis to automatically generate static pages of PHP two ways to generate static files PHP generate static HTML file in a detailed tutorial PHP generates the Smarty static page method understanding PHP Generation Static H tml File principle Php method for generating static pages |