【问题标题】:file_get_contents return strange symbols instead website content [duplicate]file_get_contents 返回奇怪的符号而不是网站内容[重复]
【发布时间】:2019-10-02 18:11:39
【问题描述】:
file_get_contents 返回奇怪的符号而不是网站内容
代码echo file_get_contents('https://olbi.su');
输出:
��}y�Ǒ��$��lcwf쮾��]�X[�--`��������8�U����)%�2�my��� �:?�ҿ��s�/���[g7��x$F� 9�,�SŞ�Dϰ7K#�.�S]U�,�o6.��]�uu��V+�...
【问题讨论】:
标签:
php
file-get-contents
【解决方案1】:
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, 'https://olbi.su');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_ENCODING , 'gzip');
$content = curl_exec ($ch);
print_r($content);
这将按照您的预期向您显示整个页面。使用 curl 库,以便您可以应用编码。