function fsubstr($title,$start,$len="",$magic=true) {/** * powered by smartpig * mailto:[email protected] */ $length = 0;if($len == "") $len = strlen($title);//判断起始为不正确位置if($start > 0){ $cnum = 0; for($i=0;$i<$start;$i++) { if(ord(substr($title,$i,1)) >= 128) $cnum ++; } if($cnum%2 != 0) $start--; unset($cnum);}if(strlen($title)<=$len) return substr($title,$start,$len);$alen = 0;$blen = 0;$realnum = 0;for($i=$start;$i =128) { $cstep = 2; $length += 2; $i += 1; $realnum ++; if($magic) { $blen ++; $ctype = 1; } }else{ $cstep = 1; $length +=1; $realnum ++; if($magic) { $alen++; } } } if($magic) { if(($blen*2+$alen) == ($len*2)) break; if(($blen*2+$alen) == ($len*2+1)) { if($ctype == 1) { $length -= $cstep; break; }else{ break; } } }else{ if($realnum == $len) break; }}unset($cur);unset($alen);unset($blen);unset($realnum);unset($ctype);unset($cstep);return substr($title,$start,$length);}
新闻热点
疑难解答