首页 >后端开发 >php教程 >Laravel与CI框架中截取字符串函数,laravelci_PHP教程

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

WBOY
WBOY原创
2016-07-12 08:53:42853浏览

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

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 = '&#8230;')
{
  if (trim($str) === '')
  {
    return $str;
  }

  preg_match('/^\s*+(&#63;:\S++\s*+){1,'.(int) $limit.'}/', $str, $matches);

  if (strlen($str) === strlen($matches[0]))
  {
    $end_char = '';
  }

  return rtrim($matches[0]).$end_char;
}

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; }...
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn