2016-02-27 98 views
0

我試圖從http://php.net/manual/en/function.file-get-contents.phpPHP的file_get_contents()函數

<?php 
    $homepage = file_get_contents('http://www.scibet.com/'); 
    echo $homepage; 
?> 

第一個例子,我只得到這樣的:

Notice: file_get_contents(): send of 16 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\xampp\htdocs\scraper\test.php on line 2 

Notice: file_get_contents(): send of 22 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\xampp\htdocs\scraper\test.php on line 2 

Notice: file_get_contents(): send of 19 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\xampp\htdocs\scraper\test.php on line 2 

Notice: file_get_contents(): send of 2 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\xampp\htdocs\scraper\test.php on line 2 

Warning: file_get_contents(http://www.scibet.com/): failed to open stream: HTTP request failed! in C:\xampp\htdocs\scraper\test.php on line 2 

問題出在哪裏?

+0

什麼是你想閱讀整個網站? –

+0

是的,我需要的方式來獲取來自外部網址的所有內容... – user3590094

+0

嘗試stream_get_contents而不是//只在網站的服務器和PHP5中允許fopen + $ handle = fopen(「http://websiteyouwanttoscrape.com/ file.html「,」r「); $ contents = stream_get_contents($ handle);一個例子,在http://stackoverflow.com/questions/34834038/php-find-and-get-value-based-on-another-one-from-html-table-parsed-file/34835046#34835046 – Steve

回答

0

您的設置可能沒有設置allow_url_fopen。您需要設置配置指令以便能夠通過HTTP打開文件,因爲默認情況下file_get_contents()僅適用於本地文件。

在這裏看到關於如何做更多的解釋: http://php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen

+0

在PHP中。 ini is allow_url_fopen = on – user3590094

+0

'$ file = file_get_contents('http://www.example.com/',false,$ context);' –

+0

'file_get_contents()只適用於本地文件'它的不正確。 –