src/TextParser.php
static function maxLengthByWords($str, $len = 50)
    {
        $str = self::removeHTMLSpecialChars($str);
        $cut = "\x1\x2\x3";
        $str = strip_tags($str);
        list($str) = explode($cut, wordwrap($str, $len, $cut));

        return $str;
    }
static function maxLengthByWords($str, $len = 50)
    {
        $str = self::removeHTMLSpecialChars($str);
        $cut = "\x1\x2\x3";
        $str = strip_tags($str);
        list($str) = explode($cut, wordwrap($str, $len, $cut));

        return $str;
    }
static function maxLengthByWords ( $ str , $ len = 50 ) { $ str = self :: removeHTMLSpecialChars ( $ str ) ; $ cut = "\x1\x2\x3" ; $ str = strip_tags ( $ str ) ; list ( $ str ) = explode ( $ cut , wordwrap ( $ str , $ len , $ cut ) ) ; return $ str ; }
This function is used to set the max length of a string without cutting the words

@param string $str The string you want to shorten
@param int    $len the string maximum length

@return null|string|string[]
This function is used to set the max length of a string without cutting the words