PHP Static implementation of code _php skills

Source: Internet
Author: User
Template file template.htm:
Copy Code code as follows:

<title>%title%</title>
<body>
<H1>%title%</H1>
<pre>%body%</pre>

</body>

PHP File:
Copy Code code as follows:

<?php
The Replace function is used to replace the keyword in the content read from the template file with the contents of the variable
function Replace ($row)
{
Define 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);
Returns the result of a replacement
return $row;
}
Template file Pointers
$f _tem = fopen ("template.htm", "R");
Generated file pointers
$f _new = fopen ("new.htm", "w");
Iterate through the template file, reading one row at a time
while (!feof ($f _tem))
{
$row = fgets ($f _tem);
$row = Replace ($row); Replace the keyword in the read content
Fwrite ($f _new, $row); Writes the replaced content to the generated HTML file
}
Close file pointer
Fclose ($f _new);
Fclose ($f _tem);
?>

To generate a new HTML page: new.html
Copy Code code as follows:

<title> article title </title>
& L T;/head>
<body>
<H1> article title </H1>
<pre> This is the article main </pre>

</body>

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.