Posted By

Gianino on 08/23/12


Tagged

php String Shortening


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

yusege


Shortening a string


 / Published in: PHP
 

Reduces the string size according to the parameter that has been send and put '...' at the end of the new string

  1. function short($txt,$size){
  2.  
  3. $short = $size - 3;
  4. if(strlen($txt) > $size){
  5. $data = substr( $txt, 0, $short )."...";
  6. }
  7. else
  8. {
  9. $data = $txt;
  10. }
  11.  
  12. return $data;
  13. }
  14.  
  15.  
  16. echo short('Gianino Cole',10);

Report this snippet  

You need to login to post a comment.