Cuts a string but without leaving incomplete words and adding a $end
string if necessary.

@param $value
@param $length
@param string $end

@return mixed|string
334972
public static function teaser($value, $length, $end = '...')
    {
        if (empty($value)) {
            return '';
        }

        $value = strip_tags($value);
        $value = preg_replace('/(\s+)/', ' ', $value);
        $long = strlen($value);

        if ($long <= $length) {
            return $value;
        }

        $pos = strrpos($value, ' ', $length - $long);
        $value = substr($value, 0, $pos ?: $length);
        return $value.$end;
    }
511142
function endsWith(longStr, shortStr) {
		var longLen = longStr.length, shortLen = shortStr.length;
		return (longLen >= shortLen) &&
			(longStr.substr(longLen - shortLen) === shortStr);
	}
1291330
public function shorter($value, int $length): bool
    {
        return is_string($value) && mb_strlen(trim($value)) <= $length;
    }
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;
    }
624383
public static function cut(string $text, int $start = 0, int $end = 0)
    {
        return Str::sub($text, $start, $end);
    }
1261081
public static function truncate($str, $length, $trailing='...') {
		$length -= mb_strlen($trailing);

		if (mb_strlen($str) > $length)
			return mb_substr($str,0,$length).$trailing;
		return $str;
	}
495785
public static function limit(string $value, int $limit = 50, string $end = self::LIMIT_SUFFIX): string
    {
        if (mb_strwidth($value, 'UTF-8') <= $limit) {
            return $value;
        }
        return rtrim(mb_strimwidth($value, 0, $limit, '', 'UTF-8')) . $end;
    }
601795
public function getValue(int $end = 0, int $length = 8): int
    {
        $result = 0;
        for ($i = $end + $length - 1; $i >= $end; $i--) {
            $result <<= 8;
            $result |= $this->bytes[$i];
        }
        return $result;
    }
581990
public function prepare($text, $length = 100, $endString = '...')
    {
        $substring = strip_tags(preg_replace('/<br.?\/?>/', ' ',$text));
        $textLength = mb_strlen($substring);
        
        if($textLength > $length) {
            $lastWordPosition = mb_strpos($substring, ' ', $length);
            
            if($lastWordPosition) {
                $substring = mb_substr($substring, 0, $lastWordPosition);
            } else {
                $substring = mb_substr($substring, 0, $length);
            }
            
            $substring.= $endString;
        }
        
        return $substring;
    }
1369995
public function truncate($value, $length, $replace = '...')
    {
        if (!isset($value)) {
            return null;
        }
        
        return strlen($value) <= $length ? $value : substr($value, 0, $length - strlen($replace)) . $replace;
    }
138383
public static function truncate($text, $length = 100)
    {
        return (self::length($text) > $length)
            ? rtrim(self::substr($text, 0, $length - 3)) . '...'
            : $text;
    }
1270845
function endsWith(str, ending) {
        if (str.length - ending.length === str.lastIndexOf(ending))
            return true;
        else return false;
    }
520755
public static function ensure_end_with($string, $trailing_string)
    {
        if (StringTool :: end_with($string, $trailing_string))
        {
            return $string;
        }
        else
        {
            return $string . $trailing_string;
        }
    }
175587
public static function truncateWords($str, $length, $trailing='...') {
		$words = explode(' ', $str);
		$cutwords = array_slice($words, 0, $length);

		return implode(' ', $cutwords).(count($words) > count($cutwords) ? $trailing:'');
	}
850677
public function endsWith($value): bool
    {
        if ($this->count() <= 0) {
            return false;
        }

        $lastValue = $this->list[$this->count() - 1];

        return ($lastValue == $value);
    }
916252
public static function truncate_two($str, $start, $length = null)
    {
        if (!$length) {
            $length = $start;
            $start = 0;
        }

        if (\strlen($str) <= $length) {
            return $str;
        }

        if (\function_exists('mb_substr')) {
            $str = mb_substr(strip_tags($str), $start, $length, 'utf-8');
        } else {
            $str = substr($str, $start, $length) . '...';
        }

        return $str;
    }
239239
public static function trimToNull(string $value = null, int $maxLength = null)
    {
        if ($value === null) {
            return null;
        }

        // trim it
        $value = trim($value);

        if (!$value) {
            return null;
        }

        if ($maxLength === 0 || $maxLength === null) {
            return $value;
        }

        return substr($value, 0, $maxLength);
    }