Posted By

jspicher on 10/09/09


Tagged

php text function truncateText


Versions (?)

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


 / Published in: PHP
 

Used to cleanly truncate text.

  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  

You need to login to post a comment.