Finds a substring with minimum length $length while preserving whole words, adds "..." to the end.
@param string $str
@param int $length
@param int $minword
422645
public static function subString($str, $length, $minword = 3, $encoding = null)
    {
        $sub = '';
        $len = 0;

        mb_internal_encoding(mb_detect_encoding($str));
        if ($encoding != null) {
            mb_internal_encoding($encoding);
        }

        foreach (explode(' ', $str) as $word) {
            $part = (($sub != '') ? ' ' : '') . $word;

            if (
                mb_strlen($word) > $minword &&
                (mb_strlen($sub) + mb_strlen($part)) >= $length
            ) {
                break;
            }
            $sub .= $part;
            $len += mb_strlen($part);
        }
        return $sub . (($len < mb_strlen($str)) ? '...' : '');
    }
1001987
public static function cutStr($str, $length=100, $postfix='...')
    {
        if ( strlen($str) < $length)
            return $str;

        $temp = substr($str, 0, $length);
        return substr($temp, 0, strrpos($temp, ' ') ) . $postfix;
    }
1173738
private static function substr($str, $start, $len)
    {
        if (function_exists('mb_substr'))
        {
            return mb_substr($str, $start, $len, 'UTF-8');
        }
        else
        {
            return substr($str, $start, $len * 2);
        }
    }
366229
public function substr($str, $offset = 0, $length = null)
    {
        // Due fix of PHP #62759 The third argument returns an empty string if is 0 or null.
        if ($length !== null) {
            return grapheme_substr($str, $offset, $length);
        }

        return grapheme_substr($str, $offset);
    }
1267613
public static function subDescription(string $text, int $length): string
    {
        return mb_strlen($text, 'utf-8') > $length ? substr($text, 0, $length - 3) . '...' : $text;
    }
685708
private function cutString($str, $length) {

        if ( mb_strlen($str, 'UTF-8') <= $length ) {
            return $str;
        }
        return mb_substr($str, 0, $length, 'UTF-8').'...';
    }
1168561
public static function substr_replace($str, $repl, $start, $length = null)
    {
        preg_match_all('/./us', $str, $ar);
        preg_match_all('/./us', $repl, $rar);
        if ($length === null) {
            $length = AnHelperString::strlen($str);
        }
        array_splice($ar[0], $start, $length, $rar[0]);
        return join('', $ar[0]);
    }
1265848
public static function truncate2(string $str, int $start, int $length = null): string
    {
        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;
    }
480466
public function fwrite(string $str, int $length = null)
    {
        $args = [$this->stream, $str];
        if (null !== $length) {
            $args[] = $length;
        }

        return fwrite(...$args);
    }
1097681
public static function substr($string, $start, $length = null)
    {
        return mb_substr($string, $start, $length, self::ENCODING);
    }
425329
protected function trim_left($string, $length) {
        return '...'.core_text::substr($string, core_text::strlen($string)-$length, $length);
    }
251389
public static function minLength($value, $param)
    {
        $length = is_array($value) ? count($value) : mb_strlen($value);

        return $length >= $param;
    }
852326
private function min($value, $min)
    {
        if (is_string($value)) {
            $value = strlen($value);
        }

        return $value >= $min;
    }
678027
public static function length_min($object, $length): bool
    {
        if (!Any::isLine($object)) {
            return false;
        }

        return Str::length((string)$object) >= $length;
    }
766015
public static function substring($string = false, $firstIndex = 0, $maxStringLength = false) {

        if ($string) {

            if (!$maxStringLength) {

                $maxStringLength = (self::length($string) - $firstIndex);
            }

            return substr($string, $firstIndex, $maxStringLength);
        }

        return false;
    }
194103
private function endsWith($str, $sub)
    {
        return substr($str, strlen($str) - strlen($sub)) === $sub;
    }
1188849
public function validateMinLength($length)
    {
        $this->validator_attributes[] = 'data-parsley-minlength="' . (int)$length . '"';

        $this->validator_checks['min_length'] = (int)$length;

        return $this;
    }