对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获取一个模板文件
然后将模板再次修改
$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之類的
相关文章
相关视频
专题推荐
-
独孤九贱-php全栈开发教程
全栈 170W+
主讲:Peter-Zhu 轻松幽默、简短易学,非常适合PHP学习入门
-
玉女心经-web前端开发教程
入门 80W+
主讲:灭绝师太 由浅入深、明快简洁,非常适合前端学习入门
-
天龙八部-实战开发教程
实战 120W+
主讲:西门大官人 思路清晰、严谨规范,适合有一定web编程基础学习
推荐阅读
-
[walkerlee原作]对PHP之函数sprintf()的学习研究笔记_PHP
-
对file_get_contents()函数的迷惑
-
C 对指针数组、数组指针 和 函数指针、函数指针数组、指向函数指针数组的指针的理解
-
PHP中fopen,file_get_contents,curl函数的区别
-
对python中的six.moves模块的下载函数urlretrieve详解
-
想对杰奇小说系统做二次开发,哪位高手知道这个系统数据库里日期函数的算法
-
python使用sorted函数对列表进行排序的方法
-
PHP中fopen,file_get_contents,curl函数的区别,curlgetcontents
-
PHP中round()函数对浮点数进行四舍五入的方法_PHP
-
PHP-CGI进程CPU 100% 与 file_get_contents 函数的关系分析_PHP教程
网友评论
文明上网理性发言,请遵守 新闻评论服务协议
我要评论