put your head on my shoulder php static implementation code

WBOY
Release: 2016-07-29 08:39:39
Original
960 people have browsed it

Template file template.htm:

Copy the code The code is as follows:




%title%

< ;body>

%title%




%body%




php File:

Copy code The code is as follows:


//The 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)
{
//Define variables for replacement
$title = "Article title";
$body = "Here is the body of the article";
//Replace keywords in parameters
$row = str_replace(" %title%", $title, $row);
$row = str_replace("%body%", $body, $row);
//Return the replaced result
return $row;
}
//Template File pointer
$f_tem = fopen("template.htm","r");
//Generated file pointer
$f_new = fopen("new.htm","w");
//Loop reading template File, read one line at a time
while(!feof($f_tem))
{
$row = fgets($f_tem);
$row = Replace($row); //Replace the keywords in the read content
fwrite($f_new, $row); //Write the replaced content into the generated HTML file
}
//Close the file pointer
fclose($f_new);
fclose($f_tem);
?>


Generate a new html page: new.html

Copy the code The code is as follows:




Article title

Article title




Here is the body of the article



The above introduces the put your head on my shoulder PHP static implementation code, including the content of put your head on my shoulder. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template