Php uses the tag replacement method to generate static pages. php static pages _ PHP Tutorial

Source: Internet
Author: User
Php uses the tag replacement method to generate static pages and php static pages. Php uses the tag replacement method to generate static pages. The php static page code demonstrates how php generates static pages through custom template pages and custom tags. The principle is very simple. php uses tag replacement to generate static pages and php static pages.

This code demonstrates how php generates static pages through custom template pages and custom tags. The principle is very simple, that is, to replace tags on the template page with dynamic data. I hope it will give you some inspiration.

Template.html template file

 {site_title} - sharejs.com

Test. php dynamic file

<? Phpheader ('content-type: text/html; charset = utf-8 '); // prevents generated page garbled characters $ title = "PHP dynamic generation of static HTML page _ script sharing "; // define the variable $ url = "http://www.sharejs.com"; $ temp_file = "temp.html"; // temporary file, or the template file $ dest_file = "dest_page.html "; // generated target page $ fp = fopen ($ temp_file, "r"); // read-only open template $ str = fread ($ fp, filesize ($ temp_file )); // read the template content $ str = str_replace ("{penglig_site_title}", $ title, $ str); // replace the content $ str = str_replace ("{penglig_site_u Rl} ", $ url, $ str); // replace content fclose ($ fp); $ handle = fopen ($ dest_file," w "); // write the fwrite ($ handle, $ str) file to be written into; // write the replaced content into the generated HTML file fclose ($ handle ); // Close the opened file and release the file pointer and related buffer echo "script alert ('generated successfully'); window. location. href = '". $ dest_file. "'; script";?>

The above is all the content of this article. I hope you will like it.

The example code demonstrates how php generates static pages through custom template pages and custom tags. The principle is very simple...

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.