2016-02-27 66 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()只适用于本地文件'它的不正确。 –