php - Get compressed contents using cURL

17,994

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

Share:
17,994
Bé Khỏe Bé Pro
Author by

Bé Khỏe Bé Pro

Novice programmer & professional pianist

Updated on June 07, 2022

Comments

  • Bé Khỏe Bé Pro
    Bé Khỏe Bé Pro almost 2 years

    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!