$str = '我';
/* 將 '我' 轉換成 '25105' 或 '我' */
// 使用 iconv
$unicode_html = base_convert(bin2hex(iconv('UTF-8', 'UCS-4', $str)), 16, 10); // 25105
// 使用 mb_convert_encoding
$unicode_html = base_convert(bin2hex(mb_convert_encoding($str, 'ucs-4', 'utf-8')), 16, 10); // 25105
// 補上 &#xxxxx;
$unicode_html = '&#' . base_convert(bin2hex(iconv("utf-8", "ucs-4", $str)), 16, 10) . ';'; // 我
// 將 我 轉回 '我'
$str = mb_convert_encoding($unicode_html, 'UTF-8', 'HTML-ENTITIES'); // '我', $unicode_html = '我'
[转]汉字 與 UNICODE 互相轉換
最新推荐文章于 2021-03-12 22:24:48 发布
本文详细介绍了如何将字符'我'转换为Unicode编码25105,并且通过HTML实体码展示,同时提供了从Unicode编码反向转换回字符的方法。
2037

被折叠的 条评论
为什么被折叠?



