标签:style io ar on bs cti amp har 字符串
public static function cn_truncate($string, $strlen = 20, $etc = ‘...‘, $keep_first_style = false, $charset = ‘utf-8‘)
{
$slen = mb_strlen($string, $charset);
if ($slen > $strlen+2)
{
$tstr = mb_substr($string, 0, $strlen, $charset);
$matches = array();
$mcount = preg_match_all("/[\x{4e00}-\x{9fa5}]/u", $tstr, $matches);
unset($matches);
$offset = ($strlen - $mcount) * 0.35;//0;//intval((3*mb_strlen($tstr,$charset)-strlen($tstr))*0.35);
return preg_replace(‘/\&\w*$/‘, ‘‘, mb_substr($string, 0, $strlen + $offset, $charset)) . $etc;
}
else
{
return $string;
}
}
标签:style io ar on bs cti amp har 字符串
原文地址:http://www.cnblogs.com/prunus/p/4128737.html