2013-02-28 31 views
0

曾經有一段時間我使用函數file_get_contents從網站獲取html數據。但今天它這麼想的,看看爲什麼我用:如何強制file_get_contents正常工作

$html = @file_get_contents('http://www.thewebsite.com/'); 
if(!$html) 
    exit("Oops. Error :)");  

這表明我的錯誤消息。所以也許他們已經阻止了連接。

請高手們如何強制功能獲取內容?

編輯:

這給這個錯誤:

Warning: file_get_contents(http://www.thewebsite.com/) 
     [<a href='function.file-get-contents'>function.file-get-contents</a>]: 
     failed to open stream: HTTP request failed! 

PS我試過其他網站,並能正常工作

+2

你忘了閱讀文檔。有幾個原因,'file_get_contents'可能無法被列出。 – 2013-02-28 10:38:37

+0

它不顯示,因爲你的重要錯誤信息''用'@'壓制了它,刪除它並編輯你的問題。 – 2013-02-28 10:41:28

+0

也許它是_thewebsite_需要修復。 – 2013-02-28 10:41:42

回答

2
  1. 刪除警告抑制誤差
  2. 打開報告
  3. 檢查error_log中的消息 您應該看到詳細的錯誤消息,而不是「糟糕」。錯誤。」那麼你就會知道爲什麼它不工作
+0

只需更新文章 – 2013-02-28 10:49:28

+0

然後嘗試谷歌錯誤消息。 http://stackoverflow.com/questions/697472/file-get-contents-returning-failed-to-open-stream-http-request-failed – 2013-02-28 10:59:11

+0

謝謝彼得這個 – 2013-02-28 12:30:56

0

根據手冊頁。 如果fopen封裝已啓用的URL可以作爲具有這種功能的文件名。 你真的檢查每個URL返回false並給了錯誤。那麼顯然,你需要檢查的設置。