blog
2014-12-27
1 阅读
utf8中文字串截取
//utf8中文字串截取
function csubstr($str,$start,$len){
preg_match_all("/[-]|[-][-]|[-][-]|[-][-][-]|[-][-][-]|[-][-][-][-]/", $str, $ar);
$x=1;
for($i=0;$i$len){
break;
}
if(ord($ar[0][$i])<128){
if($x==2){
$len=$len+1;
$x=0;
}
$x++;
}
}
return join("",array_slice($ar[0],$start,$len));
}