utf8下,strlen会把一个汉字算作两个字符,坑爹 function length($str){ $len=strlen($str); $i=0; while($i$len){ if(preg_match('/^['.chr(0xa1).'-'.chr(0xff).']+$/',$str[$i])){ $i+=2; }else{ $i+=1; } $n+=1; } Return $n;}
function length($str){ $len=strlen($str); $i=0; while($i<$len){ if(preg_match('/^['.chr(0xa1).'-'.chr(0xff).']+$/',$str[$i])){ $i+=2; }else{ $i+=1; } $n+=1; } Return $n; }