Home  >  Article  >  Backend Development  >  How to solve php curl getting garbled characters

How to solve php curl getting garbled characters

藏色散人
藏色散人Original
2020-09-11 09:47:172818browse

The solution for php curl to obtain garbled characters: first open the corresponding script file; then obtain the web page text; finally convert GB2312 through the "b_convert_How to solve php curl getting garbled characters($outPageTxt, 'utf-8','GB2312');" method to "UTF-8".

How to solve php curl getting garbled characters

Recommended: "PHP Video Tutorial"

##Problem

I want to get movie information from Movie Paradise using

curl, but garbled characters appear in the How to solve php curl getting garbled characterss, as shown in the picture:
curl 乱码

Solution

There is a

CURLOPT_ENCODING option in the official documentation. I tried it, but it actually has no use. We see that the How to solve php curl getting garbled characters is explained in the header of the page
GB2312
##It should be like thisHow to solve php curl getting garbled characters

//curl 前面的设置不冗述
//执行 curl
$outPageTxt = curl_exec($film); //outPageTxt 是得到的网页文本
curl_close($film);

//文本转码
$outPageTxt = mb_convert_How to solve php curl getting garbled characters($outPageTxt, 'utf-8','GB2312');
//把 GB2312 转到 UTF-8

echo $outPageTxt;

Instructions for use

mb_convert_How to solve php curl getting garbled characters (Output variable, code to switch to, what code to switch from)

Result

How to solve php curl getting garbled characters

The above is the detailed content of How to solve php curl getting garbled characters. 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