對file_get_contents()函數的迷惑

來源:互聯網
上載者:User
對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之類的
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.