当前位置: 首页>>代码示例>>PHP>>正文


PHP String::length方法代码示例

本文整理汇总了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", '  '));
 }
开发者ID:radypala,项目名称:maga-website,代码行数:11,代码来源:TextInput.php

示例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);
     }
 }
开发者ID:Nivl,项目名称:Ninaca_1,代码行数:7,代码来源:ValidateNumeric.class.php

示例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;
 }
开发者ID:regiss,项目名称:texyla-s-Nete1-PhP-5.2,代码行数:11,代码来源:TextInput.php

示例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);
     }
 }
开发者ID:Nivl,项目名称:Ninaca_1,代码行数:8,代码来源:ValidateString.class.php

示例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);
 }
开发者ID:phpj,项目名称:phpj,代码行数:13,代码来源:StringBuilder.php

示例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);
 }
开发者ID:Ephigenia,项目名称:harrison,代码行数:59,代码来源:SEOKeywords.php

示例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);
 }
开发者ID:Gamepay,项目名称:xp-framework,代码行数:6,代码来源:StringTest.class.php

示例8: testSampleStringSize

 function testSampleStringSize()
 {
     $sample = new String("abc");
     $this->assertEqual(3, $sample->length());
 }
开发者ID:aeberh,项目名称:php-movico,代码行数:5,代码来源:StringLengthTest.php

示例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;
}
开发者ID:evalcodenet,项目名称:net.evalcode.components.test,代码行数:15,代码来源:assertion.php

示例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;
     }
 }
开发者ID:Nivl,项目名称:Ninaca_1,代码行数:18,代码来源:Html.class.php

示例11: length

 public function length()
 {
     $str = new String($this->str);
     return $str->length();
 }
开发者ID:warunap,项目名称:haaprojects,代码行数:5,代码来源:_string_buffer_lib.php

示例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);
 }
开发者ID:radypala,项目名称:maga-website,代码行数:9,代码来源:TemplateHelpers.php

示例13: substr

 static function substr($string, $start, $length = null)
 {
     if ($length === null) {
         $length = String::length($string) - $start;
     }
     return mb_substr($string, $start, $length);
 }
开发者ID:Nivl,项目名称:Ninaca_1,代码行数:7,代码来源:String.class.php

示例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]));
 }
开发者ID:Gamepay,项目名称:xp-framework,代码行数:8,代码来源:ArrayAccessTest.class.php

示例15: append

 private function append($string_)
 {
     $this->m_console->append($string_);
     $this->m_console->flush();
     $this->m_cursor += String::length($string_);
 }
开发者ID:evalcodenet,项目名称:net.evalcode.components.test,代码行数:6,代码来源:console.php


注:本文中的String::length方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。