Trim string to certain length and insert ellipses


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



Copy this code and paste it in your HTML
  1. // Trims a string down to a certain length and inserts an ellipses if it was trimmed.
  2. function cut($str, $len=30) {
  3. if (strlen($str) > $len) {
  4. return substr($str, 0, $len-2) . '&#133';
  5. } else {
  6. return $str;
  7. }
  8. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.