PHP dynamic generation of static HTML page sample code _ php instance

Source: Internet
Author: User
This article will share with you the sample code for dynamically generating static HTML pages in PHP. For more information, see temp.html.

The Code is as follows:






{Penglig_site_title}





Test. php

The Code is as follows:


Header ('content-type: text/html; charset = UTF-8 '); // prevents generated page garbled characters
$ Title = "PHP dynamic generation of static HTML page _ script house"; // defines Variables
$ Url = "http://www.php.net /";
$ Temp_file = "temp.html"; // temporary file, which can also be a 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 content
$ Str = str_replace ("{penglig_site_url}", $ url, $ str); // replace content
Fclose ($ fp );

$ Handle = fopen ($ dest_file, "w"); // write mode to open the file to be written
Fwrite ($ handle, $ str); // write the replaced content into the generated HTML file.
Fclose ($ handle); // close open files and release file pointers and related buffers.
Echo "script" alert ('generated successfully'); window. location. href = '". $ dest_file."'; script ";
?>

Run test. php. The specific code is modified based on actual needs.

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.