<?php @header('Content-type: text/html; charset=UTF-8'); function Ctruncate($str = '', $len = 0, $etc = '...') { if(0 == $len) return ""; $str_len = preg_match_all('/[x00-x7FxC0-xFD]/', $str, $dummy); if($len >= $str_len) { return $str; } else { $newstr = mb_substr($str,0,$len,'utf-8'); return $newstr.$etc; } } $a = "a的flhjqowihvjnjxlkcoiqyeruqwheridsiomosdifgoiioqwerhiwerqwer"; echo Ctruncate($a, "10"); ?>