PHP dynamically generate static HTML page sample code

Source: Internet
Author: User
Tags html page

  This article is mainly for you to share the PHP dynamic generation of static HTML page sample code, need friends can refer to the following

Temp.html   Code as follows: <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http:// "> <html xmlns=" "> <head> <meta http-equiv=" Content-type "content=" text/html; Charset=utf-8 "/> <title>{penglig_site_title}</title> </head> <body> <iframe width=" 100% "height=" 1000px "scrolling=" yes "frameborder=" 0 "src=" {penglig_site_url} "></iframe> </body> < /html>     test.php     code is as follows: <?php header (' content-type:text/html; Charset=utf-8 ');// Prevent the generated page garbled $title = "PHP dynamic generation Static HTML page _ script home"; Define variable $url = ""; $temp _file = "temp.html"; Temporary files can also be template files $dest _file = "dest_page.html"; The generated target page   $fp = fopen ($temp _file, "R"); Read-only open template $str = Fread ($fp, FileSize ($temp _file))//Read template content   $STR = Str_replace ("{penglig_site_title}", $title, $ STR);//replace content $str = Str_replace ("{Penglig_site_url}", $url, $STR);Change Content fclose ($FP);   $handle = fopen ($dest _file, "w"); Write to open the file that needs to be written fwrite ($handle, $STR); Write the content just replaced into the generated HTML file fclose ($handle);//Close Open file, release file pointer and associated buffer echo "<script>alert" (' Build success '); Window.location.href= ' ". $dest _file." '; </script>?>       Run test.php, that can be demonstrated. The specific code is modified according to the actual requirements.  
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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: and provide relevant evidence. A staff member will contact you within 5 working days.