$tn
= 1;
$n
++;
$noc
++;
}
elseif
(194 <=
$t
&&
$t
<= 223) {
// 如果是二字节字符$n 指针后移 2 位,$tn 最后字是 2 位
$tn
= 2;
$n
+= 2;
$noc
+= 2;
}
elseif
(224 <=
$t
&&
$t
<= 239) {
// 如果是三字节(可以理解为中字词),$n 后移 3 位,$tn 最后字是 3 位
$tn
= 3;
$n
+= 3;
$noc
+= 2;
}
elseif
(240 <=
$t
&&
$t
<= 247) {
$tn
= 4;
$n
+= 4;
$noc
+= 2;
}
elseif
(248 <=
$t
&&
$t
<= 251) {
$tn
= 5;
$n
+= 5;
$noc
+= 2;
}
elseif
(
$t
== 252 ||
$t
== 253) {
$tn
= 6;
$n
+= 6;
$noc
+= 2;
}
else
{
$n
++;
}
// 超过了要取的数就跳出连续循环
if
(
$noc
>=
$length
) {
break
;
}
}
// 这个地方是把最后一个字去掉,以备加$dot
if
(
$noc
>
$length
) {
$n
-=
$tn
;
}
$strcut
=
substr
(
$string
, 0,
$n
);
}
else
{
// 并非 utf-8 编码的全角就后移 2 位
for
(
$i
= 0;
$i
<
$length
;
$i
++) {
$strcut
.= ord (
$string
[
$i
] ) > 127 ?
$string
[
$i
] .
$string
[++
$i
] :
$string
[
$i
];
}
}