当前位置:Gxlcms > PHP教程 > Laravel与CI框架中截取字符串函数,laravelci_PHP教程

Laravel与CI框架中截取字符串函数,laravelci_PHP教程

时间:2021-07-01 10:21:17 帮助过:35人阅读

Laravel与CI框架中截取字符串函数,laravelci


Laravel:

  1. function limit($value, $limit = 100, $end = '...')
  2. {
  3. if (mb_strwidth($value, 'UTF-8') <= $limit) {
  4. return $value;
  5. }
  6. return rtrim(mb_strimwidth($value, 0, $limit, '', 'UTF-8')).$end;
  7. }

Ci:

  1. function word_limiter($str, $limit = 100, $end_char = '…')
  2. {
  3. if (trim($str) === '')
  4. {
  5. return $str;
  6. }
  7. preg_match('/^\s*+(?:\S++\s*+){1,'.(int) $limit.'}/', $str, $matches);
  8. if (strlen($str) === strlen($matches[0]))
  9. {
  10. $end_char = '';
  11. }
  12. return rtrim($matches[0]).$end_char;
  13. }

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1123782.htmlTechArticleLaravel与CI框架中截取字符串函数,laravelci Laravel: function limit($value, $limit = 100, $end = '...'){ if (mb_strwidth($value, 'UTF-8') = $limit) { return $value; }...

人气教程排行