代码:
$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=模板内容,就可以替换,为什么从文件读取出来的就不行呢?

解决方案 »

  1.   

    error_reporting(E_ALL)试试?看看有没错误?
      

  2.   

    模板很简单
    <!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>
      

  3.   

    经过测试这样是没问题的,如果你这样测试也没问题的话,可能出在文件的编码上。确认文件的编码都一致$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>';
    $read_str = str_replace("{标题}","111",$read_str);
    $read_str = str_replace("{内容}","222",$read_str);
    echo($read_str);
      

  4.   

    标签换成英文是可以了,我在模板和页面里各加了以下代码,不过没有效果
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>header("Content-type: text/html; charset=utf-8");
      

  5.   

    统统保存为utf-8的格式就好了,不过我用的phpDesigner7里点另存为没有格式的选择,我用EditPlus保存的,不过没有gb2312格式,是不是中文格式只能保存为utf-8
      

  6.   

    gbk也行。 但是两个文件需要统一。再加个header 输出时避免乱码。
      

  7.   

    如果你加了这个头,那么你的文件就必须用 utf-8 编码保存