Posted in PHP onMay 08, 2016
Laravel:
function limit($value, $limit = 100, $end = '...') { if (mb_strwidth($value, 'UTF-8') <= $limit) { return $value; } return rtrim(mb_strimwidth($value, 0, $limit, '', 'UTF-8')).$end; }
Ci:
function word_limiter($str, $limit = 100, $end_char = '…') { if (trim($str) === '') { return $str; } preg_match('/^\s*+(?:\S++\s*+){1,'.(int) $limit.'}/', $str, $matches); if (strlen($str) === strlen($matches[0])) { $end_char = ''; } return rtrim($matches[0]).$end_char; }
Laravel与CI框架中截取字符串函数
- Author -
hebedich声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@