Advertisement
reggs

Untitled

Apr 5th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.54 KB | None | 0 0
  1. //Limit string length
  2. // strip tags to avoid breaking any html
  3.                                         $string = strip_tags($term->description);
  4.                                         if (strlen($string) > 204) {
  5.  
  6.                                             // truncate string
  7.                                             $stringCut = substr($string, 0, 204);
  8.                                             $endPoint = strrpos($stringCut, ' ');
  9.  
  10.                                             //if the string doesn't contain any space then it will cut without word basis.
  11.                                             $string = $endPoint? substr($stringCut, 0, $endPoint):substr($stringCut, 0);
  12.                                             $string .= '...';
  13.                                         }
  14.                                         echo $string;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement