Echo89

Text Truncation Function

Aug 1st, 2016
78
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data