/**
* p判断字节数
* @param string
s
t
r
∗
@
r
e
t
u
r
n
f
a
l
s
e
∣
i
n
t
∗
/
p
u
b
l
i
c
f
u
n
c
t
i
o
n
g
e
t
S
t
r
L
e
n
g
t
h
(
str * @return false|int */ public function getStrLength(
str∗@returnfalse∣int∗/publicfunctiongetStrLength(str)//等同于js的charCodeAt()
{
$result = array();
for($i = 0, $l = mb_strlen($str, 'utf-8');$i < $l;++$i)
{
$result[] = $this->uniord(mb_substr($str, $i, 1, 'utf-8'));
}
$num = mb_strlen($str);
for ($i=0;$i<$num ;$i++){
if(isset($result[$i]) && $result[$i] >255){
$num +=1;
}
}
return $num;
}
private 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];
}