UTF-8截取中文字符串 function Cn_Substr($string, $length) { preg_match_all("/[x01-x7f]|[xc2-xdf][x80-xbf]|xe0[xa0-xbf][x80-xbf]|[xe1-xef][x80-xbf][x80-xbf]|xf0[x90-xbf][x80-xbf][x80-xbf]|[xf1-xf7][x80-xbf][x80-xbf][x80-xbf]/", $string, $info); for($i=0; $i<count($info[0]); $i++) { $wordscut .= $info[0][$i]; $j = ord($info[0][$i]) > 127 ? $j + 2 : $j + 1; if ($j > $length - 3) { return $wordscut." ..."; } } return join('', $info[0]); } GB2312截取中文字符串 function Cn_Substrs($strs,$lens){ if (strlen($strs)<$lens) { $nstrs=$strs; }else{ $mlens=$lens; for ($i=0;$i<=strlen($strs) && $mlens>0;$i++){ $chars=substr($strs,$i,1); if(ord($chars)>0xa0 ) { $i++; $mlens -=2;; }else{ $mlens--; } } $nstrs=substr($strs,0,$i)."..."; } return $nstrs; }