對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之類的