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


PHP StringUtil::isUTF8方法代码示例

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


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

示例1: getContentPreview

 /**
  * Returns an abstract of the file content.
  * 
  * @param	array		$data
  * @return	string
  */
 protected static function getContentPreview($data)
 {
     if (!ATTACHMENT_ENABLE_CONTENT_PREVIEW || $data['isBinary'] || $data['attachmentSize'] == 0) {
         return '';
     }
     $content = '';
     try {
         $file = new File(WCF_DIR . 'attachments/attachment-' . $data['attachmentID'], 'rb');
         $content = $file->read(2003);
         $file->close();
         if (CHARSET == 'UTF-8') {
             if (!StringUtil::isASCII($content) && !StringUtil::isUTF8($content)) {
                 $content = StringUtil::convertEncoding('ISO-8859-1', CHARSET, $content);
             }
             $content = StringUtil::substring($content, 0, 500);
             if (strlen($content) < $file->filesize()) {
                 $content .= '...';
             }
         } else {
             if (StringUtil::isUTF8($content)) {
                 return '';
             }
             $content = StringUtil::substring($content, 0, 500);
             if ($file->filesize() > 500) {
                 $content .= '...';
             }
         }
     } catch (Exception $e) {
     }
     // ignore errors
     return $content;
 }
开发者ID:joaocustodio,项目名称:EmuDevstore-1,代码行数:38,代码来源:Attachments.class.php

示例2: getContentPreview

 /**
  * Returns an abstract of the file content.
  * 
  * @return	string
  */
 public function getContentPreview()
 {
     if ($this->contentPreview === null) {
         $this->contentPreview = '';
         if (ATTACHMENT_ENABLE_CONTENT_PREVIEW && !$this->isBinary && $this->attachmentSize != 0) {
             try {
                 $file = new File(WCF_DIR . 'attachments/attachment-' . $this->attachmentID, 'rb');
                 $this->contentPreview = $file->read(2003);
                 $file->close();
                 if (CHARSET == 'UTF-8') {
                     if (!StringUtil::isASCII($this->contentPreview) && !StringUtil::isUTF8($this->contentPreview)) {
                         $this->contentPreview = StringUtil::convertEncoding('ISO-8859-1', CHARSET, $this->contentPreview);
                     }
                     $this->contentPreview = StringUtil::substring($this->contentPreview, 0, 500);
                     if (strlen($this->contentPreview) < $file->filesize()) {
                         $this->contentPreview .= '...';
                     }
                 } else {
                     if (StringUtil::isUTF8($this->contentPreview)) {
                         $this->contentPreview = '';
                     } else {
                         $this->contentPreview = StringUtil::substring($this->contentPreview, 0, 500);
                         if ($file->filesize() > 500) {
                             $this->contentPreview .= '...';
                         }
                     }
                 }
             } catch (Exception $e) {
             }
             // ignore errors
         }
     }
     return $this->contentPreview;
 }
开发者ID:joaocustodio,项目名称:EmuDevstore-1,代码行数:39,代码来源:Attachment.class.php

示例3: parseKeywords

 /**
  * Parses search keywords.
  * 
  * @param	string		$keywordString
  */
 protected static function parseKeywords($keywordString)
 {
     // convert encoding if necessary
     if (CHARSET == 'UTF-8' && !StringUtil::isASCII($keywordString) && !StringUtil::isUTF8($keywordString)) {
         $keywordString = StringUtil::convertEncoding('ISO-8859-1', 'UTF-8', $keywordString);
     }
     // remove bad wildcards
     $keywordString = preg_replace('/(?<!\\w)\\*/', '', $keywordString);
     // remove search operators
     $keywordString = preg_replace('/[\\+\\-><()~]+/', '', $keywordString);
     if (StringUtil::substring($keywordString, 0, 1) == '"' && StringUtil::substring($keywordString, -1) == '"') {
         // phrases search
         $keywordString = StringUtil::trim(StringUtil::substring($keywordString, 1, -1));
         if (!empty($keywordString)) {
             self::$keywords = array_merge(self::$keywords, array(StringUtil::encodeHTML($keywordString)));
         }
     } else {
         // replace word delimiters by space
         $keywordString = preg_replace('/[.,]/', ' ', $keywordString);
         $keywords = ArrayUtil::encodeHTML(ArrayUtil::trim(explode(' ', $keywordString)));
         if (count($keywords) > 0) {
             self::$keywords = array_merge(self::$keywords, $keywords);
         }
     }
 }
开发者ID:joaocustodio,项目名称:EmuDevstore-1,代码行数:30,代码来源:KeywordHighlighter.class.php

示例4: validate

 /**
  * Validates the node for correctness.
  *
  * The following options are supported:
  *   - Node::REPAIR - If something is broken, and automatic repair may
  *                    be attempted.
  *
  * An array is returned with warnings.
  *
  * Every item in the array has the following properties:
  *    * level - (number between 1 and 3 with severity information)
  *    * message - (human readable message)
  *    * node - (reference to the offending node)
  *
  * @param int $options
  * @return array
  */
 public function validate($options = 0)
 {
     $warnings = array();
     // Checking if our value is UTF-8
     if (!StringUtil::isUTF8($this->getRawMimeDirValue())) {
         $oldValue = $this->getRawMimeDirValue();
         $level = 3;
         if ($options & self::REPAIR) {
             $newValue = StringUtil::convertToUTF8($oldValue);
             if (true || StringUtil::isUTF8($newValue)) {
                 $this->setRawMimeDirValue($newValue);
                 $level = 1;
             }
         }
         if (preg_match('%([\\x00-\\x08\\x0B-\\x0C\\x0E\\x0F])%', $oldValue, $matches)) {
             $message = 'Property contained a control character (0x' . bin2hex($matches[1]) . ')';
         } else {
             $message = 'Property is not valid UTF-8! ' . $oldValue;
         }
         $warnings[] = array('level' => $level, 'message' => $message, 'node' => $this);
     }
     // Checking if the propertyname does not contain any invalid bytes.
     if (!preg_match('/^([A-Z0-9-]+)$/', $this->name)) {
         $warnings[] = array('level' => 1, 'message' => 'The propertyname: ' . $this->name . ' contains invalid characters. Only A-Z, 0-9 and - are allowed', 'node' => $this);
         if ($options & self::REPAIR) {
             // Uppercasing and converting underscores to dashes.
             $this->name = strtoupper(str_replace('_', '-', $this->name));
             // Removing every other invalid character
             $this->name = preg_replace('/([^A-Z0-9-])/u', '', $this->name);
         }
     }
     // Validating inner parameters
     foreach ($this->parameters as $param) {
         $warnings = array_merge($warnings, $param->validate($options));
     }
     return $warnings;
 }
开发者ID:hallnewman,项目名称:webmail-lite,代码行数:54,代码来源:Property.php

示例5: validate

 /**
  * Validates the node for correctness.
  *
  * The following options are supported:
  *   - Node::REPAIR - If something is broken, and automatic repair may
  *                    be attempted.
  *
  * An array is returned with warnings.
  *
  * Every item in the array has the following properties:
  *    * level - (number between 1 and 3 with severity information)
  *    * message - (human readable message)
  *    * node - (reference to the offending node)
  *
  * @param int $options
  * @return array
  */
 public function validate($options = 0)
 {
     $warnings = array();
     // Checking if our value is UTF-8
     if (!StringUtil::isUTF8($this->value)) {
         $warnings[] = array('level' => 1, 'message' => 'Property is not valid UTF-8!', 'node' => $this);
         if ($options & self::REPAIR) {
             $this->value = StringUtil::convertToUTF8($this->value);
         }
     }
     // Checking if the propertyname does not contain any invalid bytes.
     if (!preg_match('/^([A-Z0-9-]+)$/', $this->name)) {
         $warnings[] = array('level' => 1, 'message' => 'The propertyname: ' . $this->name . ' contains invalid characters. Only A-Z, 0-9 and - are allowed', 'node' => $this);
         if ($options & self::REPAIR) {
             // Uppercasing and converting underscores to dashes.
             $this->name = strtoupper(str_replace('_', '-', $this->name));
             // Removing every other invalid character
             $this->name = preg_replace('/([^A-Z0-9-])/u', '', $this->name);
         }
     }
     // Validating inner parameters
     foreach ($this->parameters as $param) {
         $warnings = array_merge($warnings, $param->validate($options));
     }
     return $warnings;
 }
开发者ID:TamirAl,项目名称:hubzilla,代码行数:43,代码来源:Property.php

示例6: testUTF8ControlChar

 function testUTF8ControlChar()
 {
     $string = StringUtil::isUTF8(chr('0x00'));
     $this->assertEquals(false, $string);
 }
开发者ID:TamirAl,项目名称:hubzilla,代码行数:5,代码来源:StringUtilTest.php

示例7: validate

 /**
  * Validates the node for correctness.
  *
  * The following options are supported:
  *   - Node::REPAIR - If something is broken, and automatic repair may
  *                    be attempted.
  *
  * An array is returned with warnings.
  *
  * Every item in the array has the following properties:
  *    * level - (number between 1 and 3 with severity information)
  *    * message - (human readable message)
  *    * node - (reference to the offending node)
  *
  * @param int $options
  * @return array
  */
 function validate($options = 0)
 {
     $warnings = array();
     // Checking if our value is UTF-8
     if (!StringUtil::isUTF8($this->getRawMimeDirValue())) {
         $oldValue = $this->getRawMimeDirValue();
         $level = 3;
         if ($options & self::REPAIR) {
             $newValue = StringUtil::convertToUTF8($oldValue);
             if (true || StringUtil::isUTF8($newValue)) {
                 $this->setRawMimeDirValue($newValue);
                 $level = 1;
             }
         }
         if (preg_match('%([\\x00-\\x08\\x0B-\\x0C\\x0E-\\x1F\\x7F])%', $oldValue, $matches)) {
             $message = 'Property contained a control character (0x' . bin2hex($matches[1]) . ')';
         } else {
             $message = 'Property is not valid UTF-8! ' . $oldValue;
         }
         $warnings[] = array('level' => $level, 'message' => $message, 'node' => $this);
     }
     // Checking if the propertyname does not contain any invalid bytes.
     if (!preg_match('/^([A-Z0-9-]+)$/', $this->name)) {
         $warnings[] = array('level' => 1, 'message' => 'The propertyname: ' . $this->name . ' contains invalid characters. Only A-Z, 0-9 and - are allowed', 'node' => $this);
         if ($options & self::REPAIR) {
             // Uppercasing and converting underscores to dashes.
             $this->name = strtoupper(str_replace('_', '-', $this->name));
             // Removing every other invalid character
             $this->name = preg_replace('/([^A-Z0-9-])/u', '', $this->name);
         }
     }
     if ($encoding = $this->offsetGet('ENCODING')) {
         if ($this->root->getDocumentType() === Document::VCARD40) {
             $warnings[] = array('level' => 1, 'message' => 'ENCODING parameter is not valid in vCard 4.', 'node' => $this);
         } else {
             $encoding = (string) $encoding;
             $allowedEncoding = array();
             switch ($this->root->getDocumentType()) {
                 case Document::ICALENDAR20:
                     $allowedEncoding = array('8BIT', 'BASE64');
                     break;
                 case Document::VCARD21:
                     $allowedEncoding = array('QUOTED-PRINTABLE', 'BASE64', '8BIT');
                     break;
                 case Document::VCARD30:
                     $allowedEncoding = array('B');
                     break;
             }
             if ($allowedEncoding && !in_array(strtoupper($encoding), $allowedEncoding)) {
                 $warnings[] = array('level' => 1, 'message' => 'ENCODING=' . strtoupper($encoding) . ' is not valid for this document type.', 'node' => $this);
             }
         }
     }
     // Validating inner parameters
     foreach ($this->parameters as $param) {
         $warnings = array_merge($warnings, $param->validate($options));
     }
     return $warnings;
 }
开发者ID:drognisep,项目名称:Portfolio-Site,代码行数:76,代码来源:Property.php


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