views:

2945

answers:

4

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.

+1  A: 

I assume that would be gzdecode($data)... Hmmm, but it looks like that function doesn't actually exist in any release version yet. This should do the trick (worked for me).

mercator
A: 

There are several solutions proposed in the comments on the PHP page for gzdecode.

Oddthinking
+1  A: 

I use curl and:

curl_setopt($ch,CURLOPT_ENCODING , "gzip");
jonasl
A: 

@mercator

The link doesn't work now. can you send us your code

JohnsonPowder