-
- require_once("conn.php");
- if($_GET['all'])
- {
- /*Get the database record so that the 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("Failed to open the file for writing!");
- fwrite($fp,$fpcontent)or die("Failed to write the file!");
- }
- echo "";
- }
- if($_GET['part'])
- {
- /*Get the ID of the last record to facilitate the generation of html files. File name*/
- $sqlquery = "select * from $tbname 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("Failed to open the file for writing!");
- fwrite($fp,$fpcontent)or die("Failed to write the file!");
- echo "";
- }
- ?>
- Generate html
- function btnsubmit(form)
- {
- theform.submit();
- }
- echo "All updated
Partial update";
- ?>
- html>
Copy code
Articles you may be interested in:
Three methods and code details for generating static pages in PHP
Example of php generating static page function (php2html)
How to generate static pages in php (three functions)
Details on templates and caching of static files generated by PHP
A class written in php to generate static pages
How to automatically generate static pages on a virtual host at regular intervals
Two ways to generate static files with php
Detailed tutorial on generating static pages with php
Principle analysis of php generating static html files
How to generate static pages using smarty
Understand the principle of php generating static HTML files
How to generate static pages with PHP
|