Home  >  Article  >  php教程  >  CP936 converted to UTF-8

CP936 converted to UTF-8

WBOY
WBOYOriginal
2016-10-15 10:31:473911browse

I recently wrote a crawling script. Most of the content captured is normal, but a small amount of it is garbled

Detect the character encoding and the result is CP936

mb_detect_encoding(<span style="color: #800080;">$str</span>, 'GBK, gb2312, GB18030, ISO-8859-1, ASCII, UTF-8', <span style="color: #0000ff;">true</span>)

Try to convert this encoding, but the result is still garbled

mb_convert_encoding($str, 'UTF-8', 'CP936');
氓聧掳氓潞娄盲赂聙70氓虏聛猫聙聛氓陇麓莽聦楼盲潞碌7氓虏聛氓楼鲁氓颅漏猫聙聦猫垄芦忙聧聲

Finally found out that this can be transcoded

iconv('utf-8', 'latin1', $str);
iconv('utf-8','latin1//IGNORE', $str);

 

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