PHP函数实现JS语言中的charCodeAt().toString(16)

来源:互联网 发布:正方形的风管知乎 编辑:程序博客网 时间:2024/06/03 22:04

1、JS中charCodeAt()函数方法可返回指定位置的字符的 Unicode 编码而非UTF-8编码

2、

private function charAtToStr($str){$ret = array();$len = mb_strlen($str,'utf-8');for($i=0;$i<$len;$i++){$ret[] = $this->charCodeAt($str[$i],0);}return (implode("", $ret));}private function charCodeAt($str,$index){$char = mb_substr($str, $index,1,'UTF-8');if(mb_check_encoding($char,'UTF-8')){$ret = mb_convert_encoding($char, "UCS-4BE");$ret = unpack("N", $ret);$ret = dechex($ret[1]);return $ret;}else{return null;}}

原创粉丝点击