RsD0p9BK
1/20/2016 - 8:18 AM

crop_str_word2.php

function crop_str_word($text, $max_words, $sep = ' ') {
    $words = explode($sep, $text);

    if(count($words) > $max_words && $max_words > 0) {
        $text = implode(' ', array_slice($words, 0, $max_words)) . '...';
    }

    return $text;
}

// http://api.co.ua/trim-a-string-of-php-on-number-of-words.html