中文字符长度

//中文字符长度,一个中文长度为1。
function cstrlen($str){
$n = 0; $p = 0; $c = ”;
$len = strlen($str);

for($i = 0; $i < $len; $i++) {
$c = ord($str{$i});
if($c > 127) {
$p = 1;
} else {
$p = 0;
}
$i+=$p;$n++;
}

return $n;
}

Popularity: 11%

No Responses to “中文字符长度”

Leave a Reply:

Name (required):
Mail (will not be published) (required):
Website:
Comment (required):
XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>