欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php 靜態(tài)化實(shí)現(xiàn)代碼

 更新時(shí)間:2009年03月20日 00:07:01   作者:  
Replace函數(shù)用于將從模版文件中讀取的內(nèi)容中的關(guān)鍵字替換成變量中的內(nèi)容
模板文件template.htm:
復(fù)制代碼 代碼如下:

<html>
<head>
<title>%title%</title>
</head>
<body>
<H1>%title%</H1>
<hr>
<pre>%body%</pre>

</body>
</html>

php文件:
復(fù)制代碼 代碼如下:

<?php
//Replace函數(shù)用于將從模版文件中讀取的內(nèi)容中的關(guān)鍵字替換成變量中的內(nèi)容
function Replace($row)
{
//定義用來替換的變量
$title = "文章標(biāo)題";
$body = "這里是文章主體";
//替換參數(shù)中的關(guān)鍵字
$row = str_replace("%title%", $title, $row);
$row = str_replace("%body%", $body, $row);
//返回替換后的結(jié)果
return $row;
}
//模版文件指針
$f_tem = fopen("template.htm","r");
//生成的文件指針
$f_new = fopen("new.htm","w");
//循環(huán)讀取模版文件,每次讀取一行
while(!feof($f_tem))
{
$row = fgets($f_tem);
$row = Replace($row); //替換讀入內(nèi)容中的關(guān)鍵字
fwrite($f_new, $row); //將替換后的內(nèi)容寫入生成的HTML文件
}
//關(guān)閉文件指針
fclose($f_new);
fclose($f_tem);
?>

生成新的html頁:new.html
復(fù)制代碼 代碼如下:

<html>
<head>
<title>文章標(biāo)題</title>
</head>
<body>
<H1>文章標(biāo)題</H1>
<hr>
<pre>這里是文章主體</pre>

</body>
</html>

相關(guān)文章

最新評(píng)論