感谢某位兄弟写的CutString函数
function CutString($_String, $_Length, $_Start=0, $_Encode='GBK')
{
$v = 0;
if($_Encode == 'UTF-8')
{
$_Pa = "/[\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]/";
preg_match_all($_Pa, $_String, $_Rarray);
$_SLength = count($_Rarray[0]);
if($_SLength < $_Length) return $_String;
for($i=$_Start; $i<$_SLength; $i++)
{
if($v >= $_Length * 2 - 1) return $_RS.'..';
if(ord($_Rarray[0][$i]) > 129) $v += 2;
else $v++;
$_RS .= $_Rarray[0][$i];
}
} else {
$_Start = $_Start * 2;
$_Length = $_Length * 2;
$_Len = strlen($_String);
if($_Len < $_Length) return $_String;
$_Rstring= '';
for($i=$_Start; $i<$_Len; $i++)
{
if($v >= $_Length - 1) return $_Rstring.'..';
if(ord(substr($_String, $i, 1)) > 129) { $_Rstring .= substr($_String, $i, 2); $v += 2; $i++; }
else { $_Rstring .= substr($_String, $i, 1); $v++; }
}
return $_Rstring.'..';
}
}