src/Library/Helper/Text.php
public static function cut($string = '', $length = 120, $end_str = ' ...')
    {
        if (empty($string)) {
            return '';
        }
        if (strlen($string) >= $length) {
            $stringint = substr($string, 0, $length);
            $last_space = strrpos($stringint, " ");
            $stringinter = substr($stringint, 0, $last_space).$end_str;
            if (strlen($stringinter) === strlen($end_str)) {
                $stringcut = $stringint.$end_str;
            } else {
                $stringcut = $stringinter;
            }
        } else {
            $stringcut = $string;
        }
        return $stringcut;
    }
public static function cut($string = '', $length = 120, $end_str = ' ...')
    {
        if (empty($string)) {
            return '';
        }
        if (strlen($string) >= $length) {
            $stringint = substr($string, 0, $length);
            $last_space = strrpos($stringint, " ");
            $stringinter = substr($stringint, 0, $last_space).$end_str;
            if (strlen($stringinter) === strlen($end_str)) {
                $stringcut = $stringint.$end_str;
            } else {
                $stringcut = $stringinter;
            }
        } else {
            $stringcut = $string;
        }
        return $stringcut;
    }
public static function cut ( $ string = '' , $ length = 120 , $ end_str = ' ...' ) { if ( empty ( $ string ) ) { return '' ; } if ( strlen ( $ string ) >= $ length ) { $ stringint = substr ( $ string , 0 , $ length ) ; $ last_space = strrpos ( $ stringint , " " ) ; $ stringinter = substr ( $ stringint , 0 , $ last_space ) . $ end_str ; if ( strlen ( $ stringinter ) === strlen ( $ end_str ) ) { $ stringcut = $ stringint . $ end_str ; } else { $ stringcut = $ stringinter ; } } else { $ stringcut = $ string ; } return $ stringcut ; }
Truncate a string at a maximum length, adding it a suffix like '...'

@param   string  $string     The string to cut
@param   int     $length     The maximum length to keep (`120` by default)
@param   string  $end_str    The suffix to add if the string was cut (` ...` by default)
@return  string
Truncate a string at a maximum length adding it a suffix like ...