nbsp; $n=$n+0.5; //小写字母和半角标点等与半个高位字符宽... } } if ($str_length>$cutlength){ $returnstr = $returnstr . "...";//超过长度时在尾处加上省略号 } return $returnstr;
}
截取utf-8字符串函数
function FSubstr($title,$start,$len="",$magic=true) { /** * powered by Smartpig * mailto:d.einstein@263.net */
if($len == "") $len=strlen($title); if($start != 0) { $startv = ord(substr($title,$start,1)); if($startv >= 128) { if($startv < 192) { for($i=$start-1;$i>0;$i--) { $tempv = ord(substr($title,$i,1)); if($tempv >= 192) break; } $start = $i; } } } if(strlen($title)<=$len) return substr($title,$start,$len); $alen = 0; $blen = 0; $realnum = 0; for($i=$start;$i<strlen($title);$i++) { $ctype = 0; $cstep = 0; $cur = substr($title,$i,1); if($cur == "&") { if(substr($title,$i,4) == "<") { $cstep = 4; $length += 4; $i += 3; $realnum ++; if($magic) { $alen ++; } } else if(substr($title,$i,4) == ">") { $cstep = 4; $length += 4; $i += 3; $realnum ++; if($magic) { $alen ++; } } else if(substr($title,$i,5) == "&") { $cstep = 5; $length += 5; $i += 4; $realnum ++; if($magic) { $alen ++; } } else if(substr($title,$i,6) == """) { $cstep = 6; $length += 6; $i += 5; $realnum ++; if($magic) { $alen ++; } } else if(preg_match("/&#(\d+);?/i",substr($title,$i,8),$match)) { $cstep = strlen($match[0]); $length += strlen($match[0]); $i += strlen($match[0])-1; $realnum ++; if($magic) { $blen ++; $ctype = 1; |