Put your head on my shoulder php static implementation code

Source: Internet
Author: User
Template file template.htm:

Copy the Code code as follows:




%title%


%title%



%body%




PHP Files:

Copy the Code code as follows:


The Replace function is used to replace the keywords in the content read from the template file with the contents of the variable
function Replace ($row)
{
Define the variables to replace
$title = "article title";
$body = "Here is the subject of the article";
Replace a keyword in a parameter
$row = Str_replace ("%title%", $title, $row);
$row = Str_replace ("%body%", $body, $row);
Returns the replaced result
return $row;
}
Template file pointer
$f _tem = fopen ("template.htm", "R");
The generated file pointer
$f _new = fopen ("new.htm", "w");
Iterate through a template file, reading one line at a time
while (!feof ($f _tem))
{
$row = fgets ($f _tem);
$row = Replace ($row); Replace keywords in read-in content
Fwrite ($f _new, $row); Writes the replaced content to the generated HTML file
}
Close file pointer
Fclose ($f _new);
Fclose ($f _tem);
?>


Generate a new HTML page: new.html

Copy the Code code as follows:




Article title


Article title



Here is the subject of the article



The above describes the put your head on my shoulder php static implementation code, including put your head on my shoulder aspects, I hope to be interested in PHP tutorial friends helpful.

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