我已经尝试了一些使用PHP简单的HTML DOM解析器启用gzip压缩的东西,但目前为止似乎没有任何工作。使用ini_set我已经管理更改用户代理,所以我认为它也可以启用gzip压缩?如何使用PHP简单的HTML DOM解析器启用gzip压缩
include("simpdom/simple_html_dom.php");
ini_set('zlib.output_compression', 'On');
$url = 'http://www.whatsmyip.org/http_compression/';
$html = file_get_html($url);
print $html;
上面的网站测试它。请让我知道,如果我完全错误的方式。
====
UPDATE
其他任何人试图达到同样的事情,最好只使用卷曲,然后使用DOM解析器,像这样:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url); // Define target site
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); // Return page in string
curl_setopt($cr, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.2 (KHTML, like Gecko) Chrome/5.0.342.3 Safari/533.2');
curl_setopt($ch, CURLOPT_ENCODING , "gzip");
curl_setopt($ch, CURLOPT_TIMEOUT,5);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); // Follow redirects
$return = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
$html = str_get_html("$return");
但是,根据该压缩测试页,感谢回复。 。它说它仍然不能工作。 我可以压缩的唯一方法是使用cURL。 \t curl_setopt($ ch,CURLOPT_ENCODING,“gzip”); 有没有其他想法? – brant 2010-05-26 16:38:24
Pablo - 伟大的代码:)请记住,尽管如此,他在“请求”gzip内容,而不是在这种情况下发送它。他将去另一台服务器,询问数据并试图说“给我压缩,我可以处理它”。 – 2010-05-27 02:01:12