Posted By

neogeek on 06/30/06


Tagged

words substr


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

helle


Sub Sentence


 / Published in: PHP
 

Similar to substr(), only this doesn't chop up words and adds a notification if the string has been shortened.

  1. if (!function_exists('subsent')) {
  2.  
  3. function subsent($string, $start = 0, $length = 0, $cap = '...') {
  4.  
  5. if ($length <= 0 || strlen($string) < $length) { return $string; }
  6.  
  7. $string = substr($string, $start, strpos($string, ' ', $length)) . ' ' . $cap;
  8.  
  9. return $string;
  10.  
  11. }
  12.  
  13. }

Report this snippet  

You need to login to post a comment.