且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

解码通过cURL在PHP中检索的gzip压缩的网页

更新时间:2023-02-24 15:51:41

我使用curl和:

  curl_setopt($ ch,CURLOPT_ENCODING,gzip); 


I'm retrieving a gzipped web page via curl, but when I output the retrieved content to the browser I just get the raw gzipped data. How can I decode the data in PHP?

One method I found was to write the content to a tmp file and then ...

$f = gzopen($filename,"r");
$content = gzread($filename,250000);
gzclose($f);

.... but man, there's got to be a better way.

Edit: This isn't a file, but a gzipped html page returned by a web server.

I use curl and:

curl_setopt($ch,CURLOPT_ENCODING , "gzip");