Posted By

resting on 11/09/10


Tagged

limit word


Versions (?)

Modified Word limit function


 / Published in: PHP
 

modification to http://snipplr.com/view/12987/limit-words-in-a-string/

Appends ... if string is truncated.

  1. function limit_words($string, $word_limit)
  2. {
  3. $append = '';
  4. $words = explode(" ",$string);
  5. if(count($words) > $word_limit) {
  6. $append = '...';
  7. }
  8. return implode(" ",array_splice($words,0,$word_limit)) . $append;
  9. }

Report this snippet  

You need to login to post a comment.