src/Strings.php
public static function ellipsize(string $string, int $maxLength, string $suffix = '...') : string
    {
        if ($maxLength < 0) {
            throw new \InvalidArgumentException('$maxLength is negative');
        }

        if (strlen($string) <= $maxLength) {
            return $string;
        }

        $trimmedLength = $maxLength - strlen($suffix);
        $string = substr($string, 0, max(0, $trimmedLength));

        if ($string === '') {
            return substr($suffix, 0, $maxLength);
        }

        return $string . $suffix;
    }
public static function ellipsize(string $string, int $maxLength, string $suffix = '...') : string
    {
        if ($maxLength < 0) {
            throw new \InvalidArgumentException('$maxLength is negative');
        }

        if (strlen($string) <= $maxLength) {
            return $string;
        }

        $trimmedLength = $maxLength - strlen($suffix);
        $string = substr($string, 0, max(0, $trimmedLength));

        if ($string === '') {
            return substr($suffix, 0, $maxLength);
        }

        return $string . $suffix;
    }
public static function ellipsize ( string $ string , int $ maxLength , string $ suffix = '...' ) : string { if ( $ maxLength < 0 ) { throw new \ InvalidArgumentException ( '$maxLength is negative' ) ; } if ( strlen ( $ string ) <= $ maxLength ) { return $ string ; } $ trimmedLength = $ maxLength - strlen ( $ suffix ) ; $ string = substr ( $ string , 0 , max ( 0 , $ trimmedLength ) ) ; if ( $ string === '' ) { return substr ( $ suffix , 0 , $ maxLength ) ; } return $ string . $ suffix ; }
Truncates the string to the given length, with an ellipsis at the end.

@param string $string The string to shorten.
@param int $maxLength The length to truncate the string to.  The result will not be longer than this, but may be
shorter.
@param string $suffix The string to append when truncating.  Typically this will be an ellipsis.

@return string The truncated string with the ellipsis included if truncation occured.

@throws \InvalidArgumentException if $maxLength is negative
Truncates the string to the given length with an ellipsis at the end .