UTF-8安全Equantlant ord或charCodeAt()在PHP [英] UTF-8 Safe Equivelant of ord or charCodeAt() in PHP

查看:177
本文介绍了UTF-8安全Equantlant ord或charCodeAt()在PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要能够使用ord()获得与javascript的charCodeAt()函数相同的值。问题是,ord()不支持UTF8。

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.

如何在PHP中将Ą转换为260?我尝试了一些uniord功能,但他们都报告256而不是260.

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.

非常感谢任何帮助!

尊重

推荐答案

ord()每个字节(如大多数PHP标准字符串函数 - 如果不是全部)。您需要自己转换,例如在多字节字符串扩展的帮助下:

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安全Equantlant ord或charCodeAt()在PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆