sunslayer commented on a Page, Truncation  -  Feb 26, 2011
function getTrunc($n, $l) {
    if (!isset($n{$l}) { return $n; }
    $n = explode(' ', substr($n, 0, $l));
    if (count($n)>1) { unset($n[count($n)-1]); }
    return implode(' ', $n).'...';
}

your checking the size before its exploded, getTrunc(12345,2) will return 12345 instead of 12

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.