Modified Word limit function


/ Published in: PHP
Save to your folder(s)

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

Appends ... if string is truncated.


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.