@param string $key
@param int $maxlength

@return string|null
434033
public function getStringValue($key, $maxlength = null)
    {
        $value = $this->get($key);
        if ($value === null) {
            return null;
        }
        return ($maxlength === null) ? $value : substr($value, 0, $maxlength);
    }
211652
public function maxlength($length = null, $addFilter = true, $utf8 = true)
    {
        if ($addFilter) {
            $this->addFilter(new MaxLengthFilter($length, $utf8));
        }

        return $this->attr('maxlength', $length);
    }
404545
public function andBetween($key, $min, $max)
    {
        $value = sprintf('%s BETWEEN ? AND ?', $key);
        return $this->andAdd($value, [$min, $max]);
    }
1234663
static function maxLengthByWords($str, $len = 50)
    {
        $str = self::removeHTMLSpecialChars($str);
        $cut = "\x1\x2\x3";
        $str = strip_tags($str);
        list($str) = explode($cut, wordwrap($str, $len, $cut));

        return $str;
    }
1068504
static public function betweenLength($value, $minLength, $maxLength, $message = null, $propertyPath = null, $encoding = 'utf8')
        {
            static::string($value, $message);

            if (mb_strlen($value, $encoding) < $minLength) {
                $message = $message ?: sprintf(
                    'Value "%s" is too short, it should have more than %d characters, but only has %d characters.',
                    static::stringify($value),
                    $minLength,
                    mb_strlen($value, $encoding)
                );

                $constraints = array('min_length' => $minLength, 'encoding' => $encoding);

                throw static::createException($value, $message, static::INVALID_MIN_LENGTH, $propertyPath, $constraints);
            }

            if (mb_strlen($value, $encoding) > $maxLength) {
                $message = $message ?: sprintf(
                    'Value "%s" is too long, it should have no more than %d characters, but has %d characters.',
                    static::stringify($value),
                    $maxLength,
                    mb_strlen($value, $encoding)
                );

                $constraints = array('max_length' => $maxLength, 'encoding' => $encoding);

                throw static::createException($value, $message, static::INVALID_MAX_LENGTH, $propertyPath, $constraints);
            }
        }
1283896
public function maxHtmlLineLength($contents, $maxHtmlLineLength)
    {
        if (strlen($contents) <= $maxHtmlLineLength) {
            return $contents;
        }

        $result = '';
        $splits = str_split($contents, $maxHtmlLineLength);
        foreach ($splits as $split) {
            $pos = strrpos($split, '><');
            if ($pos === false) {
                $result .= $split;
            } else {
                $result .= substr_replace($split, PHP_EOL, $pos + 1, 0);
            }
        }

        return $result;
    }
977299
public function setMaximumLength($maximumLength)
    {
        if ($maximumLength <= $this->minimalLength) {
            throw new Exception\InvalidArgumentException('Maximum length must be larger than minimal length.');
        }

        $this->maximumLength = $maximumLength;

        return $this;
    }
1270482
public static function truncate(string $string, int $maxLength, string $indicator = '...'): string
    {
        if (mb_strlen($string) > $maxLength) {
            $string = mb_substr($string, 0, $maxLength - mb_strlen($indicator)) . $indicator;
        }

        return $string;
    }
1064054
public function length($min, $max = null) {
        if (!$this->_isValid) {
            return $this;
        }
        $length = mb_strlen($this->_unsafeVar, $this->conf['encoding']);
        if ($length < $min || (!is_null($max) && $length > $max)) {
            $this->_isValid = false;
        }
        return $this;
    }
456698
public function max($input, $key, $max, $lang)
    {
        $lang = $this->custom('max', $lang);
        if (strlen($input[$key]) > $max) {
            return preg_replace_callback('/(:field)(.*)(\:num)/i',
            function ($m) use ($key, $max) {
                return $key.$m[2].$max;
            }, $lang);
        }
    }
124966
public function rateLimit($key = null) {
		return $key ? (isset($this->rate_limit[$key]) ? $this->rate_limit[$key] : null) : $this->rate_limit;
	}
200611
public function rule_max( $key, $value, $max )
	{
		return $this->rule_max_num( $key, strlen( $value ), $max );
	}
1070671
public static function truncate($str, $maxlength=20)
    {

        if(strlen($str) > $maxlength){
            $str = substr($str, 0, $maxlength-3).'...';
        }

        return $str;
    }
900458
private static function printBorder(Border $border, $maxKeyLength, $maxValueLength)
    {
        $result = '';

        $keyBorderLine   = Util::buildPatternLine($border->getLineCharacter(), $maxKeyLength + 2);
        $valueBorderLine = Util::buildPatternLine($border->getLineCharacter(), $maxValueLength + 2);

        $result .= $border->getCrossCharacter() . $keyBorderLine . $border->getCrossCharacter();
        $result .= $valueBorderLine . $border->getCrossCharacter() . PHP_EOL;

        return $result;
    }
415369
public static function generateUniqueId($maxLength = null)
    {
        $entropy = '';

        // try ssl first
        if (function_exists('openssl_random_pseudo_bytes')) {
            $entropy = openssl_random_pseudo_bytes(64, $strong);
            // skip ssl since it wasn't using the strong algo
            if ($strong !== true) {
                $entropy = '';
            }
        }

        // add some basic mt_rand/uniqid combo
        $entropy .= uniqid(mt_rand(), true);

        // try to read from the windows RNG
        if (class_exists('COM')) {
            try {
                $com = new COM('CAPICOM.Utilities.1');
                $entropy .= base64_decode($com->GetRandom(64, 0));
            } catch (Exception $ex) {
            }
        }

        // try to read from the unix RNG
        if (is_readable('/dev/urandom')) {
            $h = fopen('/dev/urandom', 'rb');
            $entropy .= fread($h, 64);
            fclose($h);
        }

        $hash = hash('whirlpool', $entropy);
        if ($maxLength) {
            return substr($hash, 0, $maxLength);
        }

        return $hash;
    }
447187
protected static function stringLengthMax(int $max, RuleInterface $next = null): RuleInterface
    {
        return $next === null ?
            new StringLengthMax($max) :
            new AndOperator(static::stringLengthMax($max), $next);
    }
911242
public function strPost($key, $minLength = 0, $maxLength = false, $default = false)
	{
		return $this->str($this->post($key), $minLength, $maxLength, $default);
	}