Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/90.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何用PHP下载网站-我有一个小问题。(还是少校?)_Php_Html_Http - Fatal编程技术网

如何用PHP下载网站-我有一个小问题。(还是少校?)

如何用PHP下载网站-我有一个小问题。(还是少校?),php,html,http,Php,Html,Http,我正在学习PHP,我正在尝试制作一个与外部网站有关系的应用程序。 我需要下载它。 所以我得到了这个代码: $str = file_get_contents($url); 它将返回网站的HTML内容。 它适用于大多数网站,但对于某个特定的网站——它显示的是废话。 有什么问题?我能做些什么来修复它? 非常感谢。 实际上,您应该检查响应头,因为它们告诉您返回的数据的编码文件\u get\u内容 例如,如果它是gzip编码的,您需要解压缩它 通常您不会注意到这一点,因为file\u get\u co


我正在学习PHP,我正在尝试制作一个与外部网站有关系的应用程序。
我需要下载它。
所以我得到了这个代码:

$str = file_get_contents($url);

它将返回网站的HTML内容。
它适用于大多数网站,但对于某个特定的网站——它显示的是废话。
有什么问题?我能做些什么来修复它?
非常感谢。

实际上,您应该检查响应头,因为它们告诉您返回的数据的编码
文件\u get\u内容

例如,如果它是gzip编码的,您需要解压缩它

通常您不会注意到这一点,因为
file\u get\u contents()
发送请求的方式使服务器知道它不支持压缩

但是,有些服务器根本不在乎,还是会向您发送压缩响应:

<?php

$url = 'http://www.fxp.co.il/';

$buffer = file_get_contents($url);

echo $url, '<hr>', '<pre>', implode("\n", $http_response_header), '</pre>';

$bare = gzdecode($buffer);

echo '<hr>', htmlspecialchars(substr($bare, 0, 256));

为什么要混淆URL?内容正在以gzip方式发送?出于隐私原因,我混淆了URL。嗯-谷歌的内容也被gzip压缩了,但它们仍然表现得很好…@Quantic Programming:duh是什么意思?如果你不想你的URL是公开的,不要把它发布在公开的(CC许可的)网站上:PcURL:That's wierd-那是因为我的代码中没有这个函数本身。我从php.net复制粘贴它。。。现在它起作用了。PHP的wierd…嗯,我建议您在调试时启用错误报告:
ini\u集('display\u errors',1);错误报告(~0)
@knittl:谢谢你的关照,非常感谢@奈特尔:如果我发现了他们,我会这么做:)
http://www.fxp.co.il/
------------------------------------------------------------
HTTP/1.1 200 OK
Server: nginx/0.7.67
Date: Mon, 29 Aug 2011 19:19:55 GMT
Content-Type: text/html; charset=UTF-8
Connection: close
Set-Cookie: bb_lastvisit=1314607056; expires=Tue, 28-Aug-2012 19:12:44 GMT; path=/
Set-Cookie: bb_lastactivity=0; expires=Tue, 28-Aug-2012 19:12:44 GMT; path=/
X-Accel-Expires: 600
Cache-control: must-revalidate, post-check=0, pre-check=0
Pragma: cache
Vary: Accept-Encoding,User-Agent
Content-Encoding: gzip
Content-Length: 14170
Expires: Tue, 24 Jan 1984 08:00:00 GMT
X-Header: Boost Citrus 1.9
Cache-Control: must-revalidate, post-check=0, pre-check=0
------------------------------------------------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" dir="rtl" lang="he"> <head> <meta http-equiv="Content-Type" content="text/html; charset