/*E4 B8 AD E5 9B BD 中国1110 0100 10111000 101011011110 0101 100110111011110161 a0011 11010xxx xxxx ,1个字节110xx xxxx , 2个字节1110 xxxx, 31111 0xxxx 4...*/$str = '中华人aaa民共b和国,c万岁';function utf8sub($str,$len){ if($len <=0) return ''; $length = strlen($str); $offset=0; $chars=0; $res=''; while($chars<$len && $offset<$length){ $heigh = decbin(ord(substr($str, $offset,1))); echo $heigh ,''; if(strlen($heigh)<8){ $count=1; }else if(substr($heigh,0,3) == '110'){ $count=2; }else if(substr($heigh,0,4) == '1110'){ $count=3; }else if(substr($heigh,0,5) == '11110'){ $count=4; }else if(substr($heigh,0,6) == '111110'){ $count=5; }else if(substr($heigh,0,7) == '1111110'){ $count=6; } $res .= substr($str, $offset,$count); $chars += 1; $offset += $count; } return $res;}echo utf8sub($str,10);本2文来*源gao($daima.com搞@代@#码(网搞gaodaima代码
以上就介绍了PHP utf-8中文截取无乱码(字符串判断版本),包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。