本文整理匯總了PHP中Nette\String::length方法的典型用法代碼示例。如果您正苦於以下問題:PHP String::length方法的具體用法?PHP String::length怎麽用?PHP String::length使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Nette\String
的用法示例。
在下文中一共展示了String::length方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: checkMaxLength
/**
* Filter: shortens value to control's max length.
* @return string
*/
public function checkMaxLength($value)
{
if ($this->control->maxlength && Nette\String::length($value) > $this->control->maxlength) {
$value = iconv_substr($value, 0, $this->control->maxlength, 'UTF-8');
}
return $value;
}
示例2: sanitize
/**
* Filter: removes unnecessary whitespace and shortens value to control's max length.
* @return string
*/
public function sanitize($value)
{
if ($this->control->maxlength && Nette\String::length($value) > $this->control->maxlength) {
$value = iconv_substr($value, 0, $this->control->maxlength, 'UTF-8');
}
return Nette\String::trim(strtr($value, "\r\n", ' '));
}
示例3: validateLength
/**
* Length validator: is control's value length in range?
* @param TextBase
* @param array min and max length pair
* @return bool
*/
public static function validateLength(TextBase $control, $range)
{
if (!is_array($range)) {
$range = array($range, $range);
}
$len = String::length($control->getValue());
return ($range[0] === NULL || $len >= $range[0]) && ($range[1] === NULL || $len <= $range[1]);
}
示例4: length
/**
* Returns array of string length.
* @param mixed
* @return int
*/
public static function length($var)
{
return is_string($var) ? String::length($var) : count($var);
}