代码:
$read_str = file_get_contents("../template/HTMLPage.htm");//这是网页模板
$read_str = str_replace("{标题}","111",$read_str);
$read_str = str_replace("{内容}","222",$read_str);
echo($read_str);
最后输出的还是原模板内容,标题和内容没有被替换,但是模板的内容已经读出来了,注释掉中间两行的话可以输出模板内容。如果第一行换成直接$read_str=模板内容,就可以替换,为什么从文件读取出来的就不行呢?
$read_str = file_get_contents("../template/HTMLPage.htm");//这是网页模板
$read_str = str_replace("{标题}","111",$read_str);
$read_str = str_replace("{内容}","222",$read_str);
echo($read_str);
最后输出的还是原模板内容,标题和内容没有被替换,但是模板的内容已经读出来了,注释掉中间两行的话可以输出模板内容。如果第一行换成直接$read_str=模板内容,就可以替换,为什么从文件读取出来的就不行呢?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>模板</title>
</head>
<body style="margin:0">
<input type="hidden" id="hd_nid" />
<table align="center" width="960px" cellpadding="0" cellspacing="0" border="1">
<tr>
<td style="height:50px;text-align:center;font-size:18px;font-weight:bold">{标题}</td>
</tr>
<tr>
<td style="font-size:14px;line-height:25px">{流量}</td>
</tr>
<tr>
<td style="font-size:14px;line-height:25px">{内容}</td>
</tr>
<tr>
<td style="font-size:14px;line-height:25px">{分页}</td>
</tr>
</table>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>模板</title>
</head>
<body style="margin:0">
<input type="hidden" id="hd_nid" />
<table align="center" width="960px" cellpadding="0" cellspacing="0" border="1">
<tr>
<td style="height:50px;text-align:center;font-size:18px;font-weight:bold">{标题}</td>
</tr>
<tr>
<td style="font-size:14px;line-height:25px">{流量}</td>
</tr>
<tr>
<td style="font-size:14px;line-height:25px">{内容}</td>
</tr>
<tr>
<td style="font-size:14px;line-height:25px">{分页}</td>
</tr>
</table>
</body>
</html>';
$read_str = str_replace("{标题}","111",$read_str);
$read_str = str_replace("{内容}","222",$read_str);
echo($read_str);
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>header("Content-type: text/html; charset=utf-8");