Home  >  Article  >  Backend Development  >  How to convert big5 to utf8 in php

How to convert big5 to utf8 in php

藏色散人
藏色散人Original
2020-08-31 10:50:423788browse

php How to convert big5 to utf8: First create a PHP sample file; then use the "mb_convert_encoding($str, "UTF-8", "BIG5");" method to achieve the conversion.

How to convert big5 to utf8 in php

Recommended: "PHP Video Tutorial"

Don't think that converting big5 to utf8 is as simple as using iconv()

iconv("big5", "UTF-8", $str);

big5 There are many words that are not included:

线, embroidery, hui, cypress, peak, 鴴, village, Zhu, double

iconv This function he encountered Words that cannot be translated will stop, which may cause the output file to be interrupted and lead to file structure errors.

Please use mb_convert_encoding instead, don’t be too happy too soon. Words that big5 does not have will still not come out, but it will not get stuck because it encounters words that big5 does not recognize, although the output speed seems to be It will be slower than iconv, but the problem will be solved successfully.

Test:

$string = "轉碼測試功蓋銹abc轉碼測試"; 
$result = mb_convert_encoding($string,"utf-8","big5");
echo $result;

Usage:

mb_convert_encoding( $str, $encoding1,$encoding2 );
$str,要轉換編碼文字
$encoding1,目標編碼,如utf-8,big5,大小寫均可
$encoding2,原始編碼,如UTF-8,BIG5,大小寫均可
mb_convert_encoding($str, "UTF-8"); //編碼轉換為utf-8
mb_convert_encoding($str, "UTF-8", "BIG5"); //原始編碼為BIG5轉UTF-8
mb_convert_encoding($str, "UTF-8", "auto"); //原始編碼不明,通過auto自動檢測,轉換UTF-8

The above is the detailed content of How to convert big5 to utf8 in php. 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