app/functions.php
/**
 * Truncate a string to a specified length without cutting a word off
 *
 * @param   string  $string  The string to truncate
 * @param   int     $length  The length to truncate the string to
 * @param   string  $append  Text to append to the string IF it gets
 *                           truncated, defaults to '...'
 * @return  string
 *
 * @access  public
 * @since   1.0.0
 */
Truncate a string to a specified length without cutting a word off
@param   string  $string  The string to truncate
@param   int     $length  The length to truncate the string to
@param   string  $append  Text to append to the string IF it gets
truncated, defaults to '...'
@return  string


Truncate a string to a specified length without cutting a word off @param string $string The string to truncate @param int $length The length to truncate the string to @param string $append Text to append to the string IF it gets truncated defaults to ' ... ' @return string
function safe_truncate($string, $length, $append = '...')
{
    $ret = substr($string, 0, $length);
    $last_space = strrpos($ret, ' ');
    if ($last_space !== FALSE && $string != $ret) {
        $ret = substr($ret, 0, $last_space);
    }
    if ($ret != $string) {
        $ret .= $append;
    }
    return $ret;
}
function safe_truncate ( $ string , $ length , $ append = '...' ) { $ ret = substr ( $ string , 0 , $ length ) ; $ last_space = strrpos ( $ ret , ' ' ) ; if ( $ last_space !== FALSE && $ string != $ ret ) { $ ret = substr ( $ ret , 0 , $ last_space ) ; } if ( $ ret != $ string ) { $ ret .= $ append ; } return $ ret ; }
Truncate a string to a specified length without cutting a word off
 @param   string  $string  The string to truncate
 @param   int     $length  The length to truncate the string to
 @param   string  $append  Text to append to the string IF it gets
                           truncated, defaults to '...'
 @return  string
Truncate a string to a specified length without cutting a word off @param string $string The string to truncate @param int $length The length to truncate the string to @param string $append Text to append to the string IF it gets truncated defaults to ' ... ' @return string