/lib/Haanga/Extension/Filter/Truncatewords.php

http://github.com/crodas/Haanga · PHP · 13 lines · 12 code · 1 blank · 0 comment · 2 complexity · b726f084936531ccff773b4ef2963f2e MD5 · raw file

  1. <?php
  2. class Haanga_Extension_Filter_Truncatewords
  3. {
  4. static function main($text, $limit)
  5. {
  6. $words = explode(" ", $text, $limit+1);
  7. if (count($words) == $limit+1) {
  8. $words[$limit] = '...';
  9. }
  10. return implode(" ", $words);
  11. }
  12. }