PHP static implementation code

Source: Internet
Author: User

Template.htm: CopyCode The Code is as follows: <HTML>
<Head>
<Title> % title % </title>
</Head>
<Body>
<H1> % title % <HR>
<PRE> % body % </PRE>

</Body>
</Html>

PHP file: copy Code the code is as follows: // replace function is used to replace the keywords in the content read from the template file with the content in the variable.
function Replace ($ row)
{< br> // defines the variable to replace
$ Title = " Article title ";
$ body = "here is the subject of the article";
// Replace the keyword in the parameter
$ ROW = str_replace ("% title %", $ title, $ row);
$ ROW = str_replace ("% body %", $ body, $ row );
// return the result after replacement
return $ row;
}< br> // template file pointer
$ f_tem = fopen ("template.htm", "R ");
// generated file pointer
$ F _ New = fopen ("new.htm", "W");
// read the template file cyclically and read a row each time
while (! Feof ($ f_tem)
{< br> $ ROW = fgets ($ f_tem);
$ ROW = Replace ($ row ); // Replace the keyword in the read content
fwrite ($ f_new, $ row ); // write the replaced content to the generated HTML file
}< br> // close the file pointer
fclose ($ f_new );
fclose ($ f_tem);
?>

Generate a new HTML page: new.htmlCopy codeThe Code is as follows: <HTML>
<Head>
<Title> Article Title </title>
</Head>
<Body>
<H1> Article Title <HR>
<PRE> This is the subject of the article </PRE>

</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.