问题描述
我需要能够使用ord()来获得与javascript的charCodeAt()函数相同的值。问题是ord()不支持UTF8。
如何在PHP中将translate翻译为260?我已经尝试了一些单向函数,但它们都报告了256而不是260。
非常感谢你的帮助!
'p>此致
ORD()
工作字节每个字节(作为大多数PHP标准字符串函数 - 如果不是全部)。您将需要转换自己的,例如与多字节字符串扩展的帮助:
$ utf8Character = 'A' ;
list(,$ ord)= unpack('N',mb_convert_encoding($ utf8Character,'UCS-4BE','UTF-8'));
echo $ ord; #260
I need to be able to use ord() to get the same value as javascript's charCodeAt() function. The problem is that ord() doesn't support UTF8.
How can I get Ą to translate to 260 in PHP? I've tried some uniord functions out there, but they all report 256 instead of 260.
Thanks a lot for any help!
Regards
ord()
works byte per byte (as most of PHPs standard string functions - if not all). You would need to convert it your own, for example with the help of the multibyte string extension:
$utf8Character = 'Ą';
list(, $ord) = unpack('N', mb_convert_encoding($utf8Character, 'UCS-4BE', 'UTF-8'));
echo $ord; # 260
这篇关于UTF-8安全等效于PHP中的ord或charCodeAt()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!