limit - limit character in string

Limit the number of characters in a string.

   /**
     * Limit the number of characters in a string.
     *
     * @param  string  $value
     * @param  int     $limit
     * @param  string  $end
     * @return string
     */
  
    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;

    }

Loading ...

About the Author