PHP - UTF-16到UTF-8(十六进制)的转换

时间:2022-04-08 22:40:13

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

是否可以使用PHP将UTF-16 U+610F样式字符转换为UTF-8(十六进制)E6848F ?

UTF-8 character is '意'

utf - 8字符是“意”

2 个解决方案

#1


1  

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

从chr man页面的注释中,可以快速地将序号字符转换为UTF-8字节序列:

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

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

#2


0  

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

php有unicode编码和解码。让你试试

utf8_decode(); or utf8_encode();

#1


1  

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

从chr man页面的注释中,可以快速地将序号字符转换为UTF-8字节序列:

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

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

#2


0  

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

php有unicode编码和解码。让你试试

utf8_decode(); or utf8_encode();