All pastes #174089 Raw Edit

Mine

public text v1 · immutable
·published 2006-09-17 16:12 UTC
rendered paste body
/**
* this is a nice truncation function to break strings on a  good line
*
*/
function myTruncate($string, $limit, $break=".", $pad="...") {
    # return with no change if string is shorter than $limit 
    if(strlen($string) <= $limit) return $string;
 
    # is $break present between $limit and the end of the string?
    if(false !== ($breakpoint = strpos($string, $break, $limit))) {
      if($breakpoint < strlen($string) - 1) {
        # truncate string and pad
        $string = substr($string, 0, $breakpoint) . $pad;
      }
    }    
    return $string;
  }