Advertisement
Guest User

Untitled

a guest
Jul 30th, 2015
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. namespace WPX\Utility;
  2.  
  3. /**
  4. * Truncate
  5. *
  6. * A very simple function that limits a given block of text to the specified length.
  7. *
  8. * @since 1.0
  9. * @param string $text
  10. * @param string $limit
  11. * @param string $break The character to break on (typically a space)
  12. * @return string
  13. *
  14. */
  15. function truncate($text, $limit, $break) {
  16. $size = strlen(strip_tags($text));
  17. if ($size > $limit) {
  18. $text = $text." ";
  19. $text = substr($text,0,$limit);
  20. $text = substr($text,0,strrpos($text,' '));
  21. $text = $text.$break;
  22. }
  23. return $text;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement