0

Why does the code below code not print html content?

$url = 'http://clashofclans.com';
echo file_get_contents($url);

It works in all websites except for $url. I get this:

‹í}}{ÛÆ±ïÿùÛ[É-á…IÛrŽÍØqzœØO¤º·'ÍÕ ˆ˜$ÔK÷;¿™¾åö9µËÅîìÌì¼íìxúå×o»çÿx÷Rd£á³/žâ¢ ƒñÕi#7P½g_hÚÓQ”Z8¦i”6fYßh7NæwY61¢_fñõiãÿ{nt“Ñ$ÈâËaÔÐÂdœEcêöíËÓ¨w•;Ž 
peak
  • 105,803
  • 17
  • 152
  • 177
Ali Ahmadi
  • 89
  • 1
  • 7

1 Answers1

2

Because the response content is gzipped.

Try gzdecode:

gzdecode(file_get_contents($url));

Consider using cURL instead, which does the decompression for you and should be more robust, as described in this SO answer.

Community
  • 1
  • 1
Genti Saliu
  • 2,643
  • 4
  • 23
  • 43