PHP solves the problem of Chinese garbled characters in the returned content when curl gets the http request

Chinese garbled characters appeared when using PHP's curl to obtain remote html text. Many Baidu tutorials use the following line of code:

$str = mb_convert_encoding($str, 'utf-8','GB2312');

But this line has a drawback. If it returns utf-8 encoding instead of GB2312, then the original content that should be normal becomes garbled, so it needs to be improved as follows:

//转换字符编码
$str = mb_convert_encoding($str, 'utf-8','UTF-8,GBK,GB2312,BIG5');

 

Guess you like

Origin blog.csdn.net/qq15577969/article/details/112767563