當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。