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


PHP StringUtils::isValidUtf8方法代码示例

本文整理汇总了PHP中Zend\Stdlib\StringUtils::isValidUtf8方法的典型用法代码示例。如果您正苦于以下问题:PHP StringUtils::isValidUtf8方法的具体用法?PHP StringUtils::isValidUtf8怎么用?PHP StringUtils::isValidUtf8使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend\Stdlib\StringUtils的用法示例。


在下文中一共展示了StringUtils::isValidUtf8方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: encodeText

 /**
  * Encode a text to match console encoding
  *
  * @param  string $text
  * @return string the encoding text
  */
 public function encodeText($text)
 {
     if ($this->isUtf8()) {
         if (StringUtils::isValidUtf8($text)) {
             return $text;
         }
         return utf8_encode($text);
     }
     if (StringUtils::isValidUtf8($text)) {
         return utf8_decode($text);
     }
     return $text;
 }
开发者ID:Flesh192,项目名称:magento,代码行数:19,代码来源:AbstractAdapter.php

示例2: render

 /**
  * Render a FIGlet text
  *
  * @param  string $text     Text to convert to a figlet text
  * @param  string $encoding Encoding of the input string
  * @throws Exception\InvalidArgumentException When $text is not a string
  * @throws Exception\UnexpectedValueException When $text it not properly encoded
  * @return string
  */
 public function render($text, $encoding = 'UTF-8')
 {
     if (!is_string($text)) {
         throw new Exception\InvalidArgumentException('$text must be a string');
     }
     // Get the string wrapper supporting UTF-8 character encoding and the input encoding
     $strWrapper = StringUtils::getWrapper($encoding, 'UTF-8');
     // Convert $text to UTF-8 and check encoding
     $text = $strWrapper->convert($text);
     if (!StringUtils::isValidUtf8($text)) {
         throw new Exception\UnexpectedValueException('$text is not encoded with ' . $encoding);
     }
     $strWrapper = StringUtils::getWrapper('UTF-8');
     $this->output = '';
     $this->outputLine = array();
     $this->_clearLine();
     $this->outlineLengthLimit = $this->outputWidth - 1;
     $this->inCharLineLengthLimit = $this->outputWidth * 4 + 100;
     $wordBreakMode = 0;
     $lastCharWasEol = false;
     $textLength = $strWrapper->strlen($text);
     for ($charNum = 0; $charNum < $textLength; $charNum++) {
         // Handle paragraphs
         $char = $strWrapper->substr($text, $charNum, 1);
         if ($char === "\n" && $this->handleParagraphs && !$lastCharWasEol) {
             $nextChar = $strWrapper->substr($text, $charNum + 1, 1);
             if (!$nextChar) {
                 $nextChar = null;
             }
             $char = ctype_space($nextChar) ? "\n" : ' ';
         }
         $lastCharWasEol = ctype_space($char) && $char !== "\t" && $char !== ' ';
         if (ctype_space($char)) {
             $char = $char === "\t" || $char === ' ' ? ' ' : "\n";
         }
         // Skip unprintable characters
         $ordChar = $this->_uniOrd($char);
         if ($ordChar > 0 && $ordChar < 32 && $char !== "\n" || $ordChar === 127) {
             continue;
         }
         // Build the character
         // Note: The following code is complex and thoroughly tested.
         // Be careful when modifying!
         do {
             $charNotAdded = false;
             if ($wordBreakMode === -1) {
                 if ($char === ' ') {
                     break;
                 } elseif ($char === "\n") {
                     $wordBreakMode = 0;
                     break;
                 }
                 $wordBreakMode = 0;
             }
             if ($char === "\n") {
                 $this->_appendLine();
                 $wordBreakMode = false;
             } elseif ($this->_addChar($char)) {
                 if ($char !== ' ') {
                     $wordBreakMode = $wordBreakMode >= 2 ? 3 : 1;
                 } else {
                     $wordBreakMode = $wordBreakMode > 0 ? 2 : 0;
                 }
             } elseif ($this->outlineLength === 0) {
                 for ($i = 0; $i < $this->charHeight; $i++) {
                     if ($this->rightToLeft === 1 && $this->outputWidth > 1) {
                         $offset = strlen($this->currentChar[$i]) - $this->outlineLengthLimit;
                         $this->_putString(substr($this->currentChar[$i], $offset));
                     } else {
                         $this->_putString($this->currentChar[$i]);
                     }
                 }
                 $wordBreakMode = -1;
             } elseif ($char === ' ') {
                 if ($wordBreakMode === 2) {
                     $this->_splitLine();
                 } else {
                     $this->_appendLine();
                 }
                 $wordBreakMode = -1;
             } else {
                 if ($wordBreakMode >= 2) {
                     $this->_splitLine();
                 } else {
                     $this->_appendLine();
                 }
                 $wordBreakMode = $wordBreakMode === 3 ? 1 : 0;
                 $charNotAdded = true;
             }
         } while ($charNotAdded);
     }
//.........这里部分代码省略.........
开发者ID:eltonoliveira,项目名称:jenkins,代码行数:101,代码来源:Figlet.php

示例3: testIsValidUtf8

 /**
  * @dataProvider getUtf8StringValidity
  * @param string $str
  * @param boolean $valid
  */
 public function testIsValidUtf8($str, $valid)
 {
     $this->assertSame($valid, StringUtils::isValidUtf8($str));
 }
开发者ID:benivaldo,项目名称:zf2-na-pratica,代码行数:9,代码来源:StringUtilsTest.php

示例4: ensureUtf8Encoded

 /**
  * @param string $subject
  *
  * @return string
  */
 protected static function ensureUtf8Encoded($subject)
 {
     if (!StringUtils::isValidUtf8($subject)) {
         $subject = utf8_encode($subject);
     }
     return $subject;
 }
开发者ID:matiasvillanueva,项目名称:laravel5-CRUD-LOGIN,代码行数:12,代码来源:TemplateProcessor.php


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