Advertisement
Echo89

Text Truncation Function

Aug 1st, 2016
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.34 KB | None | 0 0
  1. function truncate($string, $length = 512, $ending = '…') {
  2.     if(mb_strlen($string) < $length) return $string;
  3.     $strip = strip_tags($string);
  4.     do {
  5.         $strip = mb_substr($strip, 0, $length);
  6.         $length--;
  7.         if($length <= 0) break;
  8.     } while(mb_strtoupper($strip[$length]) == mb_strtolower($strip[$length]));
  9.  
  10.     return $strip . $ending;
  11. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement