Ali Ahmadi Ali Ahmadi - 2 years ago 120
PHP Question

php - characters instead of html

why the below code does not echos html content:

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


It works in all websites except $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•;Ž

Answer Source

Because the response content is gzipped.

Try gzdecode:

gzdecode(file_get_contents($url));

Alternatively you can use cURL, which does the decompression for you and should be more robust, as described in this SO answer.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download