PHP - UTF-16 to UTF-8(hex) conversion

て烟熏妆下的殇ゞ 提交于 2019-12-01 11:41:25

问题


Is it possible to convert UTF-16
U+610F
style character to UTF-8 (hex)
E6848F
using PHP ?

UTF-8 character is '意'


回答1:


From the comments in the chr man page, one quick hack for turning an ordinal character number into a UTF-8 byte sequence:

function unichr($u) {
    return mb_convert_encoding('&#' . intval($u) . ';', 'UTF-8', 'HTML-ENTITIES');
}

// unichr(0x610F) -> "\xE6\x84\x8F"



回答2:


php have unicode encoding and decoding.. let u try on that

utf8_decode(); or utf8_encode();


来源:https://stackoverflow.com/questions/2670039/php-utf-16-to-utf-8hex-conversion

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!