Ali Ahmadi
Ali Ahmadi

Reputation: 89

php - characters instead of html

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•;Ž 

Upvotes: 0

Views: 38

Answers (1)

Genti Saliu
Genti Saliu

Reputation: 2723

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.

Upvotes: 2

Related Questions