今天想试试远程调用,但是很郁闷  
  我利用file_get_contents获取一个模板文件
  然后将模板再次修改
$moban = file_get_contents('http://127.0.0.1/2.html');
$htmlcontent = str_replace('{content1}',$contentreplace,$moban);
$htmlname="1.html";
file_put_contents($htmlname,$htmlcontent);  
应该都看得懂吧
 但是出现了一个问题 就是我生成出来的1.html是空白的,但是源码里面可以看到。
ps:本地调用那个1.html的时候没问题。也就是
$moban =file('2.html');
$htmlcontent = str_replace('1',$contentreplace,$moban);
$htmlname="1.html";
file_put_contents($htmlname,$htmlcontent);
这样就页面正常显示。
求解为什么原因?

解决方案 »

  1.   

    试试 file_get_contents("http://localhost/2.html");
    另外,你用的是不是80端口?
    telnet localhost 80 查看一下。
    如果不是,加上端口号。
      

  2.   

    模板是不能远程调用的经过http就是经过服务器解析了,不符合html的语法的内容就去掉了,你得到的不是原文件,是解析后的文件
      

  3.   

    你試試
    $moban = file_get_contents('http://127.0.0.1/2.html');
    echo $moban;
    $htmlcontent = str_replace('{content1}',$contentreplace,$moban);
    echo '<br>----------<br>'.$htmlcontent;
      

  4.   

    如果
    echo $moban;
    輸出的內容是空的,那麼你就要換其他方法來獲取了,例如curl之類的