时间:2021-07-01 10:21:17 帮助过:3人阅读
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; } }