Php Static Page code generation this section generates static page program implementation principle is to do a custom template tag, and then replace the tag with the specified content by str_replace, then, fopen generates a static page with the specified file name, so that it is OK.
Php tutorials generate static page code
The implementation principle of this static page generation program is to customize the template tag, then replace the tag with the specified content by str_replace, and then generate a static page with the specified file name by fopen, in this case, OK.
Header ('content-type: text/html; charset = UTF-8 ');
If (! Function_exists ('file _ get_contents ') {// if the system does not have the file_get_contents () function
Function file_get_contents ($ file) {// write the file_get_contents () function by yourself
$ Fp = fopen ($ file, 'R ');
$ Content = fread ($ fp, filesize ($ file ));
Fclose ($ fp );
Return $ content;
}
}
$ Tmp_file = 'template.html '; // Template File
$ Content = file_get_contents ($ tmp_file); // obtain the Template File content
$ Title = "title"; // value to be replaced by the template variable title
$ Text = 'text'; // value to be replaced by the template variable text
$ Content = str_replace ('<{title}>', $ title, $ content); // Replace the template variable title
$ Content = str_replace ('<{text}>', $ text, $ content); // Replace the template variable text
// Echo $ content; // display the content of the replaced Template File
Makehtml('news.html ', $ content); // The generated static file contains the news.html file.
Echo '<a href = "news.html" target = "_ blank"> View files </a> ';
Function makehtml ($ file, $ content ){
$ Fp = fopen ($ file, 'w ');
Fwrite ($ fp, $ content );
Fclose ($ fp );
}
?>
// Template.html
<! Doctype html public "-// w3c // dtd xhtml 1.0 transitional // en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "content-type" content = "text/html; charset = UTF-8"/>
<Title> makehtml </title>
</Head>
<Body>
This is the template variable title ------ <{title}>
<Br/>
This is the template variable text ------ <{text}>
</Body>
</Html>