Warm tip: This article is reproduced from stackoverflow.com, please click
decoding encoding gzip php

Decode gzipped web page retrieved via cURL in PHP

发布于 2020-05-13 17:51:50

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.

Questioner
Ian
Viewed
40
185k 2010-05-18 00:32

I use curl and:

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