开发者

Why does the chr function give unexpected output?

开发者 https://www.devze.com 2023-02-18 03:35 出处:网络
In Perl print chr(0x263a); will prin开发者_如何学Ct a perfect smiley - ☺. In PHP print chr(0x263a); will print a colon :.

In Perl print chr(0x263a); will prin开发者_如何学Ct a perfect smiley - .

In PHP print chr(0x263a); will print a colon :.

Does anyone know why?


Perl's chr function returns the character represented by that number in either ascii or unicode.

Returns the character represented by that NUMBER in the character set. For example, chr(65) is "A" in either ASCII or Unicode, and chr(0x263a) is a Unicode smiley face.

PHP's chr function is just for ascii.

Returns a one-character string containing the character specified by ascii.

The reason PHP is printing a colon is because an ascii value is between 0 and 255...

0x263a % 256 = 58

58 in ascii is a colon.


Read the chr documentation page. chr only works on ASCII values in php.

Look down that page, there are Unicode conversion helpers down in there (look for uchr for example).

0

精彩评论

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