Php generates static page code

Source: Internet
Author: User

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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.