When crawling the page, garbled characters like ������� appear. How to solve it? This article mainly shares with you the analysis of garbled pages captured by PHP. I hope it can help everyone.
1. Conversion encoding
2. The data is compressed by gzip##str, “utf-8”, “GBK”);
curl获取数据的时候设置添加下面的选项: curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
使用file_get_contents函数需要安装zlib库$data = file_get_contents("compress.zlib://".$url);
在顶部增加下面的代码header("Content-type: text/html; charset=utf-8");
php Chinese string interception Method to prevent garbled code parsing
The above is the detailed content of PHP capture page garbled analysis. For more information, please follow other related articles on the PHP Chinese website!