src/Util/Strings.php
public static function truncate(string $s, int $maxLen, string $append = "\xE2\x80\xA6"): string
    {
        if (\mb_strlen($s) > $maxLen) {
            $maxLen -= \mb_strlen($append);
            if ($maxLen < 1) {
                return $append;
            }

            if ($matches = static::match($s, '#^.{1,' . $maxLen . '}(?=[\s\x00-/:-@\[-`{-~])#us')) {
                return $matches[0] . $append;
            }

            return \mb_substr($s, 0, $maxLen) . $append;
        }

        return $s;
    }
public static function truncate(string $s, int $maxLen, string $append = "\xE2\x80\xA6"): string
    {
        if (\mb_strlen($s) > $maxLen) {
            $maxLen -= \mb_strlen($append);
            if ($maxLen < 1) {
                return $append;
            }

            if ($matches = static::match($s, '#^.{1,' . $maxLen . '}(?=[\s\x00-/:-@\[-`{-~])#us')) {
                return $matches[0] . $append;
            }

            return \mb_substr($s, 0, $maxLen) . $append;
        }

        return $s;
    }
public static function truncate ( string $ s , int $ maxLen , string $ append = "\xE2\x80\xA6" ) : string { if ( \ mb_strlen ( $ s ) > $ maxLen ) { $ maxLen -= \ mb_strlen ( $ append ) ; if ( $ maxLen < 1 ) { return $ append ; } if ( $ matches = static :: match ( $ s , '#^.{1,' . $ maxLen . '}(?=[\s\x00-/:-@\[-`{-~])#us' ) ) { return $ matches [ 0 ] . $ append ; } return \ mb_substr ( $ s , 0 , $ maxLen ) . $ append ; } return $ s ; }
Truncates string to maximal length.

@param  string $s      UTF-8 encoding
@param  int    $maxLen
@param  string $append UTF-8 encoding

@return string
Truncates string to maximal length .