本文整理汇总了PHP中String::length方法的典型用法代码示例。如果您正苦于以下问题:PHP String::length方法的具体用法?PHP String::length怎么用?PHP String::length使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类String
的用法示例。
在下文中一共展示了String::length方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sanitize
/**
* Filter: removes unnecessary whitespace and shortens value to control's max length.
* @return string
*/
public function sanitize($value)
{
if ($this->control->maxlength && String::length($value) > $this->control->maxlength) {
$value = iconv_substr($value, 0, $this->control->maxlength, 'UTF-8');
}
return String::trim(strtr($value, "\r\n", ' '));
}
示例2: maxLength
private function maxLength($value)
{
$max = $this->options['maxLength'];
if (String::length($value) > $max) {
$this->errors[] = __('The maximum length is %d number.', 'The maximum length is %d numbers.', $max);
}
}
示例3: checkMaxLength
/**
* Filter: shortens value to control's max length.
* @return string
*/
public function checkMaxLength($value)
{
if ($this->control->maxlength && String::length($value) > $this->control->maxlength) {
$value = iconv_substr($value, 0, $this->control->maxlength, 'UTF-8');
}
return $value;
}
示例4: minLength
private function minLength($value)
{
$min = (string) $this->options['min_length'];
$len = String::length($value);
if (ctype_digit($min) && $len < $min) {
$this->errors[] = __('This field must be of %d character at least.', 'This field must be of %d characters at least.', $min);
}
}
示例5: __construct
/**
* @param string|int $string
*/
public function __construct($string = null)
{
if (is_int($string)) {
parent::__construct($string);
return;
}
$string = new String($string);
parent::__construct($string->length() + 16);
$this->append($string);
}
示例6: extract
/**
* Extract Keywords from a text and return $num of them
*
* @param string $text
* @param integer $num
* @return array(string)
*/
public function extract($text, $num = null)
{
// strip html
$text = strip_tags($text);
// strip stopwords
if ($this->useStopWords) {
$text = $this->stripStopWords($text);
}
// extract long words
if ($this->collectPairs) {
$regexp = '@([A-Z][a-z]{4,}|[A-Z]{3,})([\\s-][A-Z][a-z]{3,})?@';
} else {
$regexp = '@([A-Z][a-z]{4,}|[A-Z]{3,})@';
}
if (!preg_match_all($regexp, $text, $found)) {
return array();
}
// count occurences that are used as basic score
foreach ($found[0] as $word) {
if (!isset($keywords[$word])) {
$keywords[$word] = 1;
}
$keywords[$word]++;
}
// extra scoring for word lengths and upper case words
if (!empty($this->lengthBonus)) {
$lastWordLengthBonusKey = array_keys($this->lengthBonus);
$lastWordLengthBonusKey = end($lastWordLengthBonusKey);
}
foreach ($keywords as $word => $count) {
// word length bonus
if (!empty($this->lengthBonus)) {
$wordLength = String::length($word);
if (isset($this->lengthBonus[$wordLength])) {
$keywords[$word] += $this->lengthBonus[$wordLength];
}
if ($wordLength > $this->lengthBonus[$lastWordLengthBonusKey]) {
$keywords[$word] *= 1.5;
}
}
// capital letters bonus
if (preg_match('@^[A-Z]+$@', $word)) {
$keywords[$word] += $this->capitalLetterBonus;
}
}
// sort by score
arsort($keywords);
if ($num !== null) {
$keywords = array_slice($keywords, 0, $num);
}
return array_keys($keywords);
}
示例7: offsetUnsetAtEnd
public function offsetUnsetAtEnd()
{
$str = new String('www.m�ller.com');
unset($str[$str->length() - 1]);
$this->assertEquals(new String('www.m�ller.co'), $str);
}
示例8: testSampleStringSize
function testSampleStringSize()
{
$sample = new String("abc");
$this->assertEqual(3, $sample->length());
}
示例9: assertNotEmpty
/**
* @param mixed $value_
*
* @return boolean|false If given parameter has no value.
*/
function assertNotEmpty($value_)
{
$message = Assertion_Helper::getMessage('Expected any value', __FUNCTION__, func_get_args());
if ((0 === $value_ || is_string($value_) && 1 > String::length($value_) || is_array($value_) && 1 > count($value_)) && false !== $value_) {
Assertion_Context::current()->add(__FUNCTION__, false, $message);
return false;
}
Assertion_Context::current()->add(__FUNCTION__, true, $message);
return true;
}
示例10: displayTracer
public static function displayTracer(Tracer $Tracer, $separator = ' » ', $protect = true)
{
$traces = $Tracer->getTraces();
if (!empty($traces)) {
$output = '';
foreach ($traces as $trace) {
$name = $protect ? Security::noHtml($trace['name']) : $trace['name'];
if ($trace['link']) {
$output .= Html::LinkTo($name, $trace['link']) . $separator;
} else {
$output .= $name . $separator;
}
}
return String::substr($output, 0, -String::length($separator));
} else {
return null;
}
}
示例11: length
public function length()
{
$str = new String($this->str);
return $str->length();
}
示例12: length
/**
* Returns array of string length.
* @param mixed
* @return int
*/
public static function length($var)
{
return is_string($var) ? String::length($var) : count($var);
}
示例13: substr
static function substr($string, $start, $length = null)
{
if ($length === null) {
$length = String::length($string) - $start;
}
return mb_substr($string, $start, $length);
}
示例14: stringTestChar
public function stringTestChar()
{
$s = new String('Übercoder', 'iso-8859-1');
$this->assertTrue(isset($s[0]));
$this->assertTrue(isset($s[$s->length() - 1]));
$this->assertFalse(isset($s[$s->length()]));
$this->assertFalse(isset($s[-1]));
}
示例15: append
private function append($string_)
{
$this->m_console->append($string_);
$this->m_console->flush();
$this->m_cursor += String::length($string_);
}