Friday, 9 January 2015

PHP to limit a text string to a number of words

function limit_words($string, $word_limit)
                     {
                      $words = explode(" ",$string);
                      return implode(" ",array_splice($words,0,$word_limit));
                     }
  echo limit_words($content,20);

No comments:

Post a Comment