6

I need to get content of various web pages. Some of them are compressed using different methods (gzip, deflate, etc). I've searched on the Internet and found the solution for gzipped content:

$ch = curl_init("http://games2k.net/");
curl_setopt($ch,CURLOPT_ENCODING , "gzip");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
$output = curl_exec($ch);
curl_close($ch);
echo $output;

However, this only works for a single method. I need a solution that works for as many compression methods as possible (preferably all of them) or at least the most popular two which are gzip and deflate.

Thanks very much for your help!

Bé Khỏe Bé Pro
  • 313
  • 1
  • 3
  • 9
  • Deflated content is gzippped – Anigel Jul 19 '13 at 10:40
  • Thank you @Anigel for pointing that out for me. I found that gzip actually uses DEFLATE algorithm. But people always say there are 2 popular HTTP compression methods: gzip and deflate. This really makes me confused. Anyway, I just want to know if **gzip** works for both methods or not T__T – Bé Khỏe Bé Pro Jul 19 '13 at 11:47

1 Answers1

23

did you try

$ch = curl_init("http://games2k.net/");
curl_setopt($ch,CURLOPT_ENCODING , "");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
$output = curl_exec($ch);
curl_close($ch);
echo $output;

keep the quotes empty

Deepanshu Goyal
  • 2,738
  • 3
  • 34
  • 61
  • 5
    Thank you very much, @Deepanshu! I seems that leaving the param empty works well for now. I hardly encounter compression methods other than gzip, though, and I'm still looking for more solutions and explanations. – Bé Khỏe Bé Pro Jul 19 '13 at 11:49