• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

对file_get_contents()函数的迷惑

php 搞代码 4年前 (2022-01-24) 19次浏览 已收录 0个评论

对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}’,$c/本文来源gaodai#ma#com搞*!代#%^码网%搞代gaodaima码ontentreplace,$moban);
echo ‘
———-
‘.$htmlcontent;
——解决方案——————–
如果
echo $moban;
輸出的內容是空的,那麼你就要換其他方法來獲取了,例如curl之類的


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:对file_get_contents()函数的迷惑
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址