1

为什么我没有在 file_get_contents($myurl) 上得到回报,但我确实得到了 wget 的输出

更新:

我使用 curl 来获取返回标题和结果,并发现它在标题上而不是在正文中

HTTP/1.1 200 Document follows
Transfer-Encoding: chunked
Content-type: text/plain
Server: XMS (724Solutions HTA XSAM_30_M2_B020 20070803.172831)
Date: Fri, 21 May 2010 10:48:31 GMT
Accept-Ranges: bytes

HTTP/1.1 404 ChargedPartyNotAvailable
Transfer-Encoding: chunked
Content-type: text/plain
Server: XMS (724Solutions HTA XSAM_30_M2_B020 20070803.172831)
Date: Fri, 21 May 2010 10:34:13 GMT
Accept-Ranges: bytes

如何仅提取“200 Document Follow”和“404 ChargedPartyNotAvailable”?

4

3 回答 3

6

你在你的 php 配置中启用了allow_url_fopen吗?

但是,如果没有,我希望您会收到警告-您是否显示错误/警告?您可以在脚本顶部临时添加:

error_reporting(E_ALL);
ini_set('display_errors', true);

然后你可能会明白为什么 file_get_contents() 不起作用。

编辑

get_headers()如果您只对标头感兴趣,您也许可以使用。

于 2010-05-21T09:30:25.077 回答
3

您可以使用 PHP Curl 包来检索 URL 的内容

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$myUrl);
$result = curl_exec($ch);
curl_close($ch); 

或者如果您只想使用 file_get_contents,请检查您是否正确配置了 PHP.ini

http://www.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen

如此处所述(http://php.net/manual/en/function.file-get-contents.php

如果启用了 fopen 包装器,则 URL 可以用作此函数的文件名。有关如何指定文件名的更多详细信息,请参阅 fopen()。

于 2010-05-21T09:27:57.300 回答
0

你可以试试:

$contents = implode('', file($myurl));

我经常使用它。

于 2010-05-21T10:25:02.137 回答