//截取函数
function get_len($str){
$len = 0;
for($i=0;$i<strlen($str);$i++){
if(ord($str[$i]) >= 65 && ord($str[$i]) <= 90){
$len += 1;
}elseif(ord($str[$i]) < 127){
$len += 1;
}else{
$i += 2;
$len += 2;
}
}
return $len;
}
function sub_len($str,$len){
//UTF8
$point = 0;
$return = “”;
$length = 0;
while($length <= $len){
if(ord($str[$point]) >= 65 && ord($str[$point]) <= 90){
$return .= $str[$point++];
$length += 1;
}elseif(ord($str[$point]) <128){
$return .= $str[$point++];
$length += 1;
}else{
$return = $return . $str[$point++] . $str[$point++] . $str[$point++];
$length += 2;
}
}
return $return;
}
function str_cut($str,$len){
if(get_len($str) > $len){
$title = sub_len($str,$len).”…”;
}else{
$title = $str;
}
return $title;
}
//
这个函数还是不错的,我用了,达到效果 了!