Home > Backend Development > PHP Tutorial > PHP static implementation code_PHP tutorial

PHP static implementation code_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-21 15:47:03
Original
830 people have browsed it

Template file template.htm:

Copy code The code is as follows:



%title%


%title%


%body%





php file:
Copy code The code is as follows:

//The Replace function is used to read from the template file Replace the keywords in the content with the content in the variable
function Replace($row)
{
//Define the variable used for replacement
$title = "Article Title";
$ body = "This is the body of the article";
//Replace the keywords in the parameters
$row = str_replace("%title%", $title, $row);
$row = str_replace(" %body%", $body, $row);
//Return the replacement result
return $row;
}
//Template file pointer
$f_tem = fopen(" template.htm","r");
//Generated file pointer
$f_new = fopen("new.htm","w");
//Loop to read the template file, each Read one line at a time
while(!feof($f_tem))
{
$row = fgets($f_tem);
$row = Replace($row); //Replace the read content Keywords in
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 code The code is as follows:



Article title


Article title




This is the body of the article


< /body>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/320042.htmlTechArticleTemplate file template.htm: Copy the code as follows: html head title%title%/title /head body H1% title%/H1 hr pre%body%/pre /body /html php file: Copy the code as follows: ?php /...
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template