RsD0p9BK
1/20/2016 - 8:12 AM

crop_str_word.php

function crop_str_word($text, $max_words = 50, $sep = ' ') {
    $words = split($sep, $text);
    
    if ( count($words) > $max_words ) {
        $text  = join($sep, array_slice($words, 0, $max_words));
        $text .= ' ...';
    }
    
    return $text;
}

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