欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

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

程序员文章站 2022-05-16 21:51:28
...

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

Laravel:

function limit($value, $limit = 100, $end = '...')
{
  if (mb_strwidth($value, 'UTF-8') 

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;
}

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; }...