bone282 commented on a Page, Truncate  -  Mar 14, 2009

Here's what i use. It doesn't leave any chopped word on the end.
Very handy for long strings..

<?php 
function do_TrimString($string, $MaxSTRLEN = null) {
    if ($MaxSTRLEN == null) { global $MaxSTRLEN; }
    if (strlen($string) > $MaxSTRLEN) {
        $string = substr($string, 0, $MaxSTRLEN);
        $end = strrpos($string, ' ');
        if ($end === false) {
            $end = $MaxSTRLEN;
            }
        $string = substr($string, 0, $end) . '...';
        }
    return $string;
    }
?>
 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.