Now the CMS basically support the article generated HTML, the benefits of generating HTML static Web page does not have to say, whether it is the page to open the browsing speed, or conducive to search engine optimization seo, there are obvious improvements, sometimes the Web page has more or less loopholes, converting PHP into HTML format also protects the Web site effectively.
PHP to generate HTML technology than the ASP technology is relatively simple, the following brief how to use PHP batch generation HTML technology bar, first look at the following source:
copy code code is as follows:
!--? php if ( $_post[button] {
$sql = "SELECT * from Doorsjk_about where id<12";
$rs = $db->query ($sql);
while ($row = $db->fetch_array ($rs)) {
$path = ' list12 '. $row [id]. HTML ';
$fp =fopen (".. /group/about.html "," R ");
$str =fread ($fp, FileSize (". /group/about.html "));
$str =str_replace ("{title}", $row [title], $STR);
$str =str_replace ("{name}", $system [' name '], $STR);
$str =str_replace ("{content}", $row [content], $STR);
$str =str_replace ("{copyright}", $system [' copyright '], $str);
Fclose ($FP);
$handle =fopen (".. /group/". $path," w ");
Fwrite ($handle, $STR);
Echo "is generating";
echo "$path";
Fclose ($handle);
}
Echo "";
}
?>
First of all, the code that connects the database is included, here is a click of the form, when the button buttons are accepted, the direct loop generated HTML, here $path= ' list12′. $row [id]. HTML '; Is the generated file name, while $fp=fopen (". /group/about.html "," R ") is an open template file, just make your own desired HTML file can be, here with the Str_replace function to do the replacement tag, so you can call in HTML like {title} Such tags generate HTML files, extrapolate, simple HTML batch generation is made.
In the HTML file, the call tag is: {title}, which is directly transferred to the Read database file: $row [title], if the volume of data is large, can be segmented batch generation, is the generation of ID: from () to (). Use limit to accept the call. As for the HTML in the use of dynamic files, such as static after the statistics of the article read the number of times, this dynamic call can be encapsulated into a JS file, embedded in the line.
Here is the bulk of the regeneration, in fact, in addition to the news when the generation of HTML files, editing the content of the text generated HTML files, in fact, the principle is similar, I will write down, can make a reference.
http://www.bkjia.com/PHPjc/756680.html www.bkjia.com true http://www.bkjia.com/PHPjc/756680.html techarticle now the CMS basically support the article generated HTML, the benefits of generating HTML static Web page no need to say it, whether it is the page open browsing speed, or conducive to search engine optimization seo, ...