Home > Backend Development > PHP Problem > How to solve the problem of Chinese garbled text in PHP using curl to obtain text

How to solve the problem of Chinese garbled text in PHP using curl to obtain text

WJ
Release: 2023-03-01 10:30:01
Original
3144 people have browsed it

How to solve the problem of Chinese garbled text in PHP using curl to obtain text

Solution to the problem of Chinese garbled characters in php using curl to obtain text:

The solution code is as follows:

$url = "www.php.cn";
//获取页面内容
$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

Related Reference: php中文网

The above is the detailed content of How to solve the problem of Chinese garbled text in PHP using curl to obtain text. 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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
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