public static function limitByWords($str, $wordCount = 10)
  {
    // Reads amount of words in paragraph
    $words = preg_split("/[\s]+/", $str, $wordCount + 1);

    // limit paragraph to $wordCount value
    $words = array_slice($words, 0, $wordCount);

    // Return the words back
    return join(' ', $words);
  }
public static function limitByWords($str, $wordCount = 10)
  {
    // Reads amount of words in paragraph
    $words = preg_split("/[\s]+/", $str, $wordCount + 1);

    // limit paragraph to $wordCount value
    $words = array_slice($words, 0, $wordCount);

    // Return the words back
    return join(' ', $words);
  }
public static function limitByWords ( $ str , $ wordCount = 10 ) { // Reads amount of words in paragraph $ words = preg_split ( "/[\s]+/" , $ str , $ wordCount + 1 ) ; // limit paragraph to $wordCount value $ words = array_slice ( $ words , 0 , $ wordCount ) ; // Return the words back return join ( ' ' , $ words ) ; }
Returns a string limited by the word count specified
logic borrowed from StackOverflow

@see http://stackoverflow.com/questions/79960/how-to-truncate-a-string-in-php-to-the-word-closest-to-a-certain-number-of-chara#answer-10026115
@param  string  $str        paragraph to limit by words
@param  integer $wordCount  amount to wordCount paragraph to
@return string              string with int limitation set
Returns a string limited by the word count specified logic borrowed from StackOverflow