Laravel:
PHP;">
function limit($value,$limit = 100,$end = '...')
{
if (mb_strwidth($value,'UTF-8') <= $limit) {
return $value;
}
return rtrim(mb_strimwidth($value,$limit,'','UTF-8')).$end;
}
Ci:
PHP;">
function word_limiter($str,$end_char = '…')
{
if (trim($str) === '')
{
return $str;
}
原文链接:https://www.f2er.com/laravel/19837.htmlpreg_match('/^\s+(?:\S++\s+){1,'.(int) $limit.'}/',$str,$matches);
if (strlen($str) === strlen($matches[0]))
{
$end_char = '';
}
return rtrim($matches[0]).$end_char;
}