Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.24 KB | None | 0 0
  1. //truncate a string only at a whitespace
  2. function truncate($text, $length) {
  3. $length = abs((int)$length);
  4. if(strlen($text) > $length) {
  5. $text = preg_replace("/^(.{1,$length})(\s.*|$)/s", '\\1...', $text);
  6. }
  7. return($text);
  8. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement