<code>$url = "http://i.ifeng.com/"; $str = file_get_contents($url); var_dump($str); </code>
The result is garbled, how to fix it? Please help me, thank you very much!
Waiting online
<code>$url = "http://i.ifeng.com/"; $str = file_get_contents($url); var_dump($str); </code>
The result is garbled, how to fix it? Please help me, thank you very much!
Waiting online
There are two main reasons for garbled characters, one is the GZIP compression problem, and the other is the encoding problem. For PHP, it is not very suitable to use file_get_contents to get the content of a web page. I recommend using curl. Its stability is unparalleled, and it can be solved whether it is http or https.
Just set the encoding. You try it
<code>header("Content-Type:text/html;charset=utf-8"); $url = "http://i.ifeng.com/"; $str = file_get_contents($url); var_dump($str);</code>
Find a way
<code>file_get_contents("compress.zlib://".$url);</code>