Search code examples
phpfile-get-contents

file_get_contents return strange symbols instead website content


file_get_contents return strange symbols instead website content

Code echo file_get_contents('https://olbi.su');

Output:

��}y�Ǒ��$��lcwf쮾��]�X[�--`��������8�U����)%�2�my����:?<�"Ekx ���_a?ɋ_d�G���(-�ə��#22"22223j�ܳ/>�ҿ��s�/���[g7��x$F�9�,�SŞ�Dϰ7K#�. �S]U�,�o6.��]�uu��V+�...


Solution

  • $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);
    

    This will show you the whole page like you expect. Use curl library so you can apply encoding.