Jyxo\StringUtil::cutWords PHP Method

cutWords() public static method

String is delimited by whitespaces. If a word is trimmed, an "etc" is added at the end. Its length is also considered.
public static cutWords ( string $string, integer $length = 25, string $etc = '...' ) : string
$string string Processed string
$length integer Maximum word length
$etc string "etc" definition
return string
    public static function cutWords(string $string, int $length = 25, string $etc = '...') : string
    {
        return preg_replace_callback('~[^\\s]{' . $length . ',}~', function ($matches) use($length, $etc) {
            return StringUtil::cut($matches[0], $length, $etc);
        }, $string);
    }