Posted By

bluecap on 04/01/11


Tagged

php trim String truncate


Versions (?)

Trim extra characters from string (truncate string)


 / Published in: PHP
 

URL: http://www.bluecapwebdesign.com

If a string exceeds x characters (defaults to 100), trims the string to the first x characters and appends a tail to the end of the truncated string (defaults to an ellipsis).

  1. function trimExtraChars($string, $max = 100, $tail = '...') {
  2. if (strlen($string) > $max) {
  3. $string = substr($string, 0, $max) . $tail;
  4. }
  5.  
  6. return $string;
  7. }

Report this snippet  

You need to login to post a comment.