public static function trimmer($text, $len = false, $ellipsis = ' ...')
    {
        if (!preg_match('/[0-9]+/i', $len)) {
            $parts = explode($len, $text);

            return static::closeOpenTags($parts[0]);
        }

        $len = $len === false || !is_numeric($len) || $len <= 0 ? 600 : $len;
        $text = static::filterText($text);
        $textLen = mb_strlen($text);

        if ($textLen > $len) {
            return mb_substr($text, 0, $len) . $ellipsis;
        }

        return $text;
    }
public static function trimmer($text, $len = false, $ellipsis = ' ...')
    {
        if (!preg_match('/[0-9]+/i', $len)) {
            $parts = explode($len, $text);

            return static::closeOpenTags($parts[0]);
        }

        $len = $len === false || !is_numeric($len) || $len <= 0 ? 600 : $len;
        $text = static::filterText($text);
        $textLen = mb_strlen($text);

        if ($textLen > $len) {
            return mb_substr($text, 0, $len) . $ellipsis;
        }

        return $text;
    }
public static function trimmer ( $ text , $ len = false , $ ellipsis = ' ...' ) { if ( ! preg_match ( '/[0-9]+/i' , $ len ) ) { $ parts = explode ( $ len , $ text ) ; return static :: closeOpenTags ( $ parts [ 0 ] ) ; } $ len = $ len === false || ! is_numeric ( $ len ) || $ len <= 0 ? 600 : $ len ; $ text = static :: filterText ( $ text ) ; $ textLen = mb_strlen ( $ text ) ; if ( $ textLen > $ len ) { return mb_substr ( $ text , 0 , $ len ) . $ ellipsis ; } return $ text ; }
Safely trim a text.

This method is HTML aware, it will not "destroy" any HTML tag. You can trim
the text to a given number of characters, or you can give a string as second
argument which will be used to cut the given text and return the first part.

## Examples:

$text = '
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Fusce augue nulla, iaculis adipiscing risus sed, pharetra tempor risus.
<!-- readmore -->
Ut volutpat nisl enim, quic sit amet quam ut lacus condimentum volutpat in eu magna.
Phasellus a dolor cursus, aliquam felis sit amet, feugiat orci. Donec vel consec.';

echo $this->trimmer($text, '<!-- readmore -->');

// outputs:
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Fusce augue nulla, iaculis adipiscing risus sed, pharetra tempor risus.

echo $this->trimmer('Lorem ipsum dolor sit amet, consectetur adipiscing elit', 10);
// out: "Lorem ipsu ..."

@param string $text The text to trim
@param string|int|false $len Either a string indicating where to cut the
text, or a integer to trim text to that number of characters. If not given
(false by default) text will be trimmed to 600 characters length.
@param string $ellipsis Will be used as ending and appended to the trimmed
string. Defaults to ` ...`
@return string
Safely trim a text .