Home > Backend Development > PHP Problem > How to solve curl php Chinese garbled problem

How to solve curl php Chinese garbled problem

藏色散人
Release: 2023-03-03 12:38:02
Original
5680 people have browsed it

The solution to curl php Chinese garbled code: first open the corresponding PHP code file; then use "mb_convert_encoding($res, 'UTF-8', 'UTF-8,GBK,GB2312,BIG5');" Method to transcode the results.

How to solve curl php Chinese garbled problem

Recommended: "PHP Tutorial"

php usage The solution to the Chinese garbled code when curl obtains text

Chinese garbled code appears when using php's curl to obtain remote html text.

The solution code is as follows:

$url = "www.ecjson.com";
//获取页面内容
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT,20);
$res = curl_exec($ch);
curl_close($ch);
$res=mb_convert_encoding($res, 'UTF-8', 'UTF-8,GBK,GB2312,BIG5');//使用该函数对结果进行转码
Copy after login

The above is the detailed content of How to solve curl php Chinese garbled problem. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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
Latest Issues
curl simulated login
From 1970-01-01 08:00:00
0
0
0
Convert cURL command line to PHP cURL code
From 1970-01-01 08:00:00
0
0
0
Convert command line cURL to PHP cURL
From 1970-01-01 08:00:00
0
0
0
How to set boolean value true in php curl
From 1970-01-01 08:00:00
0
0
0
Please tell me, php curl request page shows blank
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template