truncateText($string, $limit, $break=" ", $pad="...")


/ Published in: PHP
Save to your folder(s)

Used to cleanly truncate text.


Copy this code and paste it in your HTML
  1. function truncateText($string, $limit, $break=" ", $pad="..."){
  2. if(strlen($string) <= $limit) return $string;
  3. $string = substr($string, 0, $limit);
  4. if(false !== ($breakpoint = strrpos($string, $break))) {
  5. $string = substr($string, 0, $breakpoint);}
  6. return $string . $pad;}

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.