开发者

php unicode 16 bit

开发者 https://www.devze.com 2023-03-19 15:40 出处:网络
how can I append a 16 bit u开发者_StackOverflownicode character to a string in php $test = \"testing\" . (U + 199F);

how can I append a 16 bit u开发者_StackOverflownicode character to a string in php

$test = "testing" . (U + 199F);

From what I see, \x only takes 8 bit characters aka ascii


From the manual:

PHP only supports a 256-character set, and hence does not offer native Unicode support.

You could enter a manually-encoded UTF-8 sequence, I suppose.

You can also type out UCS4 as byte sequence and use iconv("UTF-32LE", "UTF-8", $str); to convert it into UTF-8 for further processing. You just can't input the codepoint as a 32-bit code unit in one go.


Unicode characters don't directly exist in PHP(*), but you can deal with strings containing bytes represent characters in UTF-8 encoding. Here's one way of converting a numeric character code point to UTF-8:

function unichr($i) {
    return iconv('UCS-4LE', 'UTF-8', pack('V', $i));
}

$test= 'testing'.unichr(0x199F);

(*: and ‘16-bit’ Unicode characters don't exist at all; Unicode has code points way beyond U+FFFF. There are 16-bit ‘code units’ in UTF-16, but that's an ugly encoding you're unlikely to meet in PHP.)


Because unicode is just multibyte and PHP only supports single byte you can create multibyte characters with multiple single bytes :)

$test = "testing\x19\x9F";


Try:

$test = "testing" . "\u199F";
0

精彩评论

暂无评论...
验证码 换一张
取 消