Shortening a string


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

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


Copy this code and paste it in your HTML
  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


Comments


You need to login to view comments.