PHP capture page garbled analysis

小云云
Release: 2023-03-22 14:24:02
Original
2234 people have browsed it

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');
Copy after login
使用file_get_contents函数需要安装zlib库$data = file_get_contents("compress.zlib://".$url);
Copy after login

3. Garbled characters are displayed after obtaining the data

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

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!