PHP dynamic generation static HTML page sample code _php instance

Source: Internet
Author: User

Temp.html

Copy Code code as follows:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title>{penglig_site_title}</title>

<body>
<iframe width= "100%" height= "1000px" scrolling= "yes" frameborder= "0" src= "{Penglig_site_url}" ></iframe>
</body>

test.php

Copy Code code as follows:

<?php
Header (' content-type:text/html charset=utf-8 ');//Prevent the generated page from garbled
$title = "PHP dynamic generation static HTML page _ cloud Habitat Community"; Defining variables
$url = "http://www.jb51.net/";
$temp _file = "temp.html"; Temporary files, or 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 the contents of the template

$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 to open files that need to be written
Fwrite ($handle, $STR); Write what you just replaced into the generated HTML file
Fclose ($handle);//Close Open file, release file pointer and associated buffer
echo "<script>alert (' generate success '); Window.location.href= '". $dest _file. "'; </script> ";
?>

Run test.php, that can be demonstrated. The specific code is modified according to the actual requirements.

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.