Php html generation technology is simpler than ASP technology. the following briefly describes how to generate HTML in batches using PHP. Currently, CMS supports generating HTML in articles, the benefits of generating HTML static web pages do not need to be discussed. Both the speed of page opening and SEO optimization are significantly improved. sometimes there are more or less vulnerabilities in web pages, converting PHP to HTML format also effectively protects websites.
The HTML generation technology in PHP is simpler than that in ASP. the following briefly describes how to generate HTML in batches in PHP. let's take a look at the source code:
The code is as follows:
If ($ _ POST [button]) {
$ SQL = "select * from doorsjk_about where id <12 ";
$ Rs = $ db-> query ($ SQL );
While ($ row = $ db-> fetch_array ($ rs )){
Using path='list12'.w.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 "generating ";
Echo "$ path ";
Fclose ($ handle );
}
Echo "script alert ('generated successfully! '); Window. location. href = 'onlyhtml. php'; script ";
}
?>
First, the code for connecting to the database is included. The following is a click form. when the button is received, HTML is generated cyclically. the generated pathpattern 'list12).w.row+id=.'.html 'is the name of the generated file, and $ fp = fopen ("... /group/about.html "," r "); is the opened template file. you only need to make the desired HTML file. here, use the str_replace function to replace the tag, in this way, you can call tags similar to {title} in HTML to generate HTML files. In other words, simple HTML is generated in batch.
Call the tag {title} in the HTML file to directly tune it to the file $ row [title] in the read Database. if the data volume is large, it can be generated in batches in segments, is to generate ID: from (). Use limit to accept calls. As for the dynamic files used in HTML, such as generating static files and counting the number of articles read, this dynamic call can be encapsulated into JS files and embedded.
Here we will introduce the batch re-generation. In fact, HTML files are generated when news is entered, and HTML files are generated when the content of the article is edited. In fact, the principles are similar. I will write them down for reference.