How to convert big5 to utf8 in php

藏色散人
Release: 2023-03-05 14:22:02
Original
3670 people have browsed it

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);
Copy after login

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;
Copy after login

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
Copy after login

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!

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 Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!