0
$url = 'https://api.stackexchange.com/2.2/answers/'.$id.'?order=desc&sort=activity&site=stackoverflow&filter=!-*f(6t*ZdXeu&key=MY_KEY';
gzdecode(file_get_contents ($url)) ;

this caused me problems today when I played with stackoverflow APIs

btlr.com
  • 139
  • 5

1 Answers1

0

alternative approach - just use CURL, it does decompression automatically

$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_TIMEOUT, 400); 
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); // Follow redirects, need this if the url changes
curl_setopt($curl, CURLOPT_MAXREDIRS, 5); //if http server gives redirection responce
curl_setopt($curl, CURLOPT_ENCODING, "gzip"); // the page encoding

$data = curl_exec($curl); // data already decompressed
curl_close($curl);
Musa
  • 96,336
  • 17
  • 118
  • 137
btlr.com
  • 139
  • 5