UTF-8 轉 BIG5 運用 mb_convert_encoding() 的處理方式

function utf8conv2charset($utf8str, $charset='big5',$encode='utf-8'){
mb_regex_encoding($charset); // 宣告 要進行 regex 的多位元編碼轉換格式 為 $charset
mb_substitute_character('long'); // 宣告 缺碼字改以U+16進位碼為標記取代
$utf8str = mb_convert_encoding($utf8str, $charset, $encode);
$utf8str = preg_replace('/U\+([0-9A-F]{4})/e', '"&#".intval("\\1",16).";"', $utf8str); //U+16進位碼標記轉換為UnicodeHTML碼
return $utf8str;
}

随机文章:

1、C#中MessageBox用法大全
https://www.onexin.net/c-messagebox-usage-daquan/

2、如何在Apache环境下配置Rewrite规则
https://www.onexin.net/how-to-configure-rewrite-rules-apache-environment/

3、配置Gmail邮件客户端的POP3和SMTP
https://www.onexin.net/configure-gmail-e-mail-client-pop3-and-smtp/

4、Discuz!X同步好友到漫游应用
https://www.onexin.net/discuz-x-sync-friends-to-roaming-applications/

5、JavaScript函数声明和函数表达式
https://www.onexin.net/javascript-function-declaration-and-function-expression/

转载请注明出处:https://www.onexin.net/the-use-of-utf-8-transfer-big5-mb_convert_encoding-approach/

Leave a Reply

Your email address will not be published. Required fields are marked *