Return a short version of a strings

@param       string $string      The string to be shortened
@param       int $length         The maximum length of the string that is to be shown
@return string
772406
protected function short($string, $length = 200)
    {
        if( strlen( $string ) < $length ) {
            return $string;
        }

        return substr( $string, 0, $length ) .'...';
    }
690451
static function End($string, $length = 0)
    {    
        self::InitEncoding();
        $pos = max(0, self::Length($string) - $length);
        return self::Part($string, $pos);
    }
1068252
public function write($string)
    {
        $length = strlen($string);

        $start = substr($this->resource, 0, $this->pointer);
        $end = substr($this->resource, $this->pointer + $length);

        $this->resource = $start . $string . $end;

        $this->pointer = strlen($start . $string);

        return $string;
    }
35550
public function max($str, $length)
    {
        return $this->notempty($str) && strlen(trim($str)) <= $length;
    }
774391
public static function maxStrlen(array $string)
    {
        $length = 0;
        foreach ($string as $str) {
            if (strlen($str) > $length) {
                $length = strlen($str);
            }
        }

        return $length;
    }
757331
public static function last($string, $length = 1, $encoding = null)
    {
        if ($string === '' || $length <= 0) {
            return '';
        }

        $encoding = $encoding === null ? mb_internal_encoding() : $encoding;

        return Mbstring::substr($string, -$length, null, $encoding);
    }
414976
public static short stringToShort(String string) {
        string = string.trim();
        if (Checker.isNumber(string)) {
            return Short.parseShort(string);
        }
        return -1;
    }
960849
public static function shorten(string $text = '', ?int $charCount = null, bool $fullWords = true,
                                   string $suffix = '...'): string
    {
        $text = StripTags::strip($text);
        $text = \htmlspecialchars_decode((string)$text, ENT_COMPAT | ENT_HTML5);
        $text = \trim(\preg_replace('/\s+/', ' ', $text));

        if ($charCount === null || \mb_strlen($text, 'UTF-8') <= $charCount) {
            return $text;
        }

        if ($fullWords === true) {
            $shortened = \mb_substr($text, 0, $charCount, 'UTF-8');
            while (!\in_array(\mb_substr($shortened, -1, 1, 'UTF-8'), static::$wordEndingChars)) {
                $shortened = \mb_substr($shortened, 0, -1, 'UTF-8');
            }
        }
        if ($fullWords !== true) {
            $shortened = \mb_substr($text, 0, $charCount, 'UTF-8');
        }

        while (\in_array(\mb_substr($shortened, -1, 1, 'UTF-8'), static::$wordEndingChars)) {
            $shortened = \mb_substr($shortened, 0, -1, 'UTF-8');
        }

        return $shortened.$suffix;
    }
33121
public static function Substring ($string, $start, $length = null, $encoding = Encoding::DEFAULT_ENCODING) {
		if ($length === null) {
			$length = self::Length($string) - $start;
		}
		return mb_substr($string, $start, $length, $encoding);
	}
171033
public static function low($string): string
    {
        $cleaned = Str::low($string);
        $cleaned = Str::trim($cleaned);

        return $cleaned;
    }
514910
public static function str_split($s, $length = null)
	{
		if (! ReflectionTypeHint::isValid()) return false;
		if (is_null($s)) return $s;

		$length = ($length === null) ? 1 : intval($length);
		if ($length < 1) return false;
		#there are limits in regexp for {min,max}!
		if (preg_match_all('~.~suSX', $s, $m) === false) return false;
		if (function_exists('preg_last_error') && preg_last_error() !== PREG_NO_ERROR) return false;
		if ($length === 1) $a = $m[0];
		else
		{
			$a = array();
			for ($i = 0, $c = count($m[0]); $i < $c; $i += $length) $a[] = implode('', array_slice($m[0], $i, $length));
		}
		return $a;
	}
440819
public static function shorten($string, $limit = 25, $glue = ' &hellip; ') {
        if (mb_strlen($string) > $limit) {
            $width = round($limit / 2);

            // prefix
            $pre = mb_substr($string, 0, $width);

            if (mb_substr($pre, -1) !== ' ' && ($i = static::lastIndexOf($pre, ' '))) {
                $pre = mb_substr($pre, 0, $i);
            }

            // suffix
            $suf = mb_substr($string, -$width);

            if (mb_substr($suf, 0, 1) !== ' ' && ($i = static::indexOf($suf, ' '))) {
                $suf = mb_substr($suf, $i);
            }

            return trim($pre) . $glue . trim($suf);
        }

        return $string;
    }
75932
public static function rtrimWord($string, $word)
    {
        $end = mb_substr($string, 0-mb_strlen($word));
        if ($end != $word) {
            return $string;
        }
        return mb_substr($string, 0, mb_strlen($string)-mb_strlen($word));
    }
1349853
public static function shortenThis($str, int $length = null): string
    {
        if (!$length) {
            $length = 255;
        }

        if ($length > 255) {
            throw new \ErrorException('The length argument should be 255 or less.');
        }

        /**
         * [:space:] removes \t as well
         * http://stackoverflow.com/questions/2326125/remove-multiple-whitespaces
         * http://www.php.net/manual/en/regexp.reference.character-classes.php
         */
        $str = mb_ereg_replace(
            '[[:space:]]+',
            ' ',
            strip_tags($str),
            'ms'
        );
        $length = abs((int)$length - 1);

        /**
         * allow to only remove all special chars and html entities without shortening the string
         */
        if ($length === null) {
            return $str;
        }

        if (\strlen($str) > $length) {
            $str = mb_ereg_replace(
                '^(.{1,' . $length . '})([^\s]+)(\s.*|$)',
                '\\1\\2…',
                $str, 'ms'
            );
        }

        return $str;
    }
916377
public static function shortenString($str, $length = 75, $break = '...') {
        if (strlen($str) < $length)
            return $str;

        $str = strip_tags($str);

        return substr($str, 0, $length) . $break;
    }
406054
public static function truncate(
        $string,
        $length,
        $suffix = '',
        $wordBreak = true,
        $encoding = null
    ) {
        $encoding = $encoding === null ? mb_internal_encoding() : $encoding;

        if ($length >= Mbstring::strlen($string, $encoding)) {
            return $string;
        }

        $result = Mbstring::substr($string, 0, $length, $encoding);

        if (!$wordBreak && Mbstring::strpos($result, ' ', 0, $encoding) !== $length) {
            $position = Mbstring::strrpos($result, ' ', 0, $encoding);
            $result = Mbstring::substr($result, 0, $position, $encoding);
        }

        return $result . $suffix;
    }
1181681
public static function mb_str_split($string, $length = 1)
    {
        $array = [];
        $stringLength = mb_strlen($string, 'UTF-8');
    
        for ($i = 0; $i < $stringLength; $i += $length) {
            $array[] = mb_substr($string, $i, $length, 'UTF-8');
        }
    
        return $array;
    }