欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

对file_get_contents()函数的迷惑

程序员文章站 2024-01-01 17:42:10
...
对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之類的
对file_get_contents()函数的迷惑

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。

相关文章

相关视频


网友评论

文明上网理性发言,请遵守 新闻评论服务协议

我要评论
  • 对file_get_contents()函数的迷惑
  • 专题推荐

    上一篇:

    下一篇: