当前位置:Gxlcms > PHP教程 > 对file_get_contents()函数的迷惑

对file_get_contents()函数的迷惑

时间:2021-07-01 10:21:17 帮助过:18人阅读

对file_get_contents()函数的疑惑
今天想试试远程调用,但是很郁闷
我利用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);
这样就页面正常显示。
求解为什么原因?


------解决方案--------------------
试试 file_get_contents("http://localhost/2.html");
另外,你用的是不是80端口?
telnet localhost 80 查看一下。
如果不是,加上端口号。
------解决方案--------------------
你試試
$moban = file_get_contents('http://127.0.0.1/2.html');
echo $moban;
$htmlcontent = str_replace('{content1}',$contentreplace,$moban);
echo '
----------
'.$htmlcontent;
------解决方案--------------------
如果
echo $moban;
輸出的內容是空的,那麼你就要換其他方法來獲取了,例如curl之類的

人气教程排行