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•;Ž 
1
  • it's gzipped content, used for minimize data transfers over the network Commented Feb 7, 2016 at 16:32

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.