Home  >  Article  >  Backend Development  >  PHP capture page garbled analysis

PHP capture page garbled analysis

小云云
小云云Original
2018-03-28 13:23:022285browse

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

##str, “utf-8”, “GBK”);

2. The data is compressed by gzip

curl获取数据的时候设置添加下面的选项:
curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
使用file_get_contents函数需要安装zlib库$data = file_get_contents("compress.zlib://".$url);

3. Garbled characters are displayed after obtaining the data

在顶部增加下面的代码header("Content-type: text/html; charset=utf-8");

Related recommendations:


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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn