日期:2014-05-17 浏览次数:20414 次
function smarty_modifier_mb_truncate($string, $length = 80, $etc = '...', $charset='UTF-8', $break_words = false, $middle = false) { if ($length == 0) return ''; if (mb_strlen($string) > $length) { $length -= min($length, mb_strlen($etc)); if (!$break_words && !$middle) { $string = preg_replace('/\s+?(\S+)?$/u', '', mb_substr($string, 0, $length+1, $charset)); } if(!$middle) { return mb_substr($string, 0, $length, $charset) . $etc; } else { return mb_substr($string, 0, $length/2, $charset) . $etc . mb_substr($string, -$length/2, (mb_strlen($string)-$length/2), $charset); } } else { return $string; } }