请知悉:本文最近一次更新为 7年 前,文中内容可能已经过时。

charCodeAt()函数方法可返回指定位置的字符的 Unicode 编码。这个返回值是 0 – 65535 之间的整数。
JavaScript里经常看到charCodeAt函数但有些时候需要转换为php,找了一下,有篇博客提到了,代码如下:

function get_bianma($str){
$result = array();
for($i = 0, $l = mb_strlen($str, "utf-8");$i < $l;++$i){
$result[] = uniord(mb_substr($str, $i, 1, "utf-8"));
}
return join(",", $result);
}
function uniord($str, $from_encoding = false){
$from_encoding = $from_encoding $from_encoding : "UTF-8";
if (strlen($str) == 1){return ord($str);}
$str = mb_convert_encoding($str, "UCS-4BE", $from_encoding);
$tmp = unpack("N", $str);
return $tmp[1];
}

代码整理自:https://www.hhtjim.com/the-php-version-of-the-charcodeat-function.html


如您从本文得到了有价值的信息或帮助,请考虑扫描文末二维码捐赠和鼓励。

尊重他人劳动成果。转载请务必附上原文链接,我将感激不尽。


与《PHP-charCodeAt()函数》相关的博文:


发布时间 11/06/2016 09:31:20栏目 Software.标签 .

留言

avatar
😀
😀😁😂😅😭🤭😋😘🤔😰😱🤪💪👍👎🤝🌹👌