src/Zicht/Bundle/FrameworkExtraBundle/Twig/Extension.php
public function truncate($str, $length, $ellipsis = '...')
    {
        $result = '';
        foreach (preg_split('/\b/U', $str) as $part) {
            if (strlen($result . $part) > $length) {
                $result = rtrim($result) . $ellipsis;
                break;
            } else {
                $result .= $part;
            }
        }

        return $result;
    }
public function truncate($str, $length, $ellipsis = '...')
    {
        $result = '';
        foreach (preg_split('/\b/U', $str) as $part) {
            if (strlen($result . $part) > $length) {
                $result = rtrim($result) . $ellipsis;
                break;
            } else {
                $result .= $part;
            }
        }

        return $result;
    }
public function truncate ( $ str , $ length , $ ellipsis = '...' ) { $ result = '' ; foreach ( preg_split ( '/\b/U' , $ str ) as $ part ) { if ( strlen ( $ result . $ part ) > $ length ) { $ result = rtrim ( $ result ) . $ ellipsis ; break ; } else { $ result .= $ part ; } } return $ result ; }
Truncate text at a maximum length, splitting by words, and add an ellipsis "...".

@param string $str
@param int $length
@param string $ellipsis
@return string
Truncate text at a maximum length splitting by words and add an ellipsis ... .