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


PHP Codec::detectEncoding方法代码示例

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


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

示例1: whitelist

 /**
  * Returns the supplied input string after removing any characters not
  * present in the supplied whitelist.
  *
  * @param string $input     string input to be filtered.
  * @param string $whitelist array or string of whitelist characters.
  *
  * @return string returns characters from $input that are present in $whitelist.
  */
 public function whitelist($input, $whitelist)
 {
     // Sanity check
     if (!is_string($input) || $input == '') {
         $input = '';
     }
     if (is_string($whitelist)) {
         $charEnc = Codec::detectEncoding($whitelist);
         $limit = mb_strlen($whitelist, $charEnc);
         $ary = array();
         for ($i = 0; $i < $limit; $i++) {
             $ary[] = mb_substr($whitelist, $i, 1, $charEnc);
         }
         $whitelist = $ary;
     }
     $filtered = '';
     $initialCharEnc = Codec::detectEncoding($input);
     $_4ByteCharacterString = Codec::normalizeEncoding($input);
     $limit = mb_strlen($_4ByteCharacterString, 'UTF-32');
     for ($i = 0; $i < $limit; $i++) {
         $c = mb_substr($_4ByteCharacterString, $i, 1, 'UTF-32');
         if (Codec::containsCharacter($c, $whitelist)) {
             $filtered .= $c;
         }
     }
     if ($filtered != '') {
         $filtered = mb_convert_encoding($filtered, $initialCharEnc, 'UTF-32');
     }
     if (!is_string($filtered)) {
         $filtered = '';
     }
     return $filtered;
 }
开发者ID:AnvilStriker,项目名称:owasp-esapi-php,代码行数:42,代码来源:BaseValidationRule.php

示例2: encodeCharacter

 public function encodeCharacter($dummy_place_holder, $input)
 {
     $detectedCharacterEncoding = Codec::detectEncoding($input);
     $c = mb_substr($input, 0, 1, $detectedCharacterEncoding);
     return $this->encode($c, false);
 }
开发者ID:neelaryan,项目名称:mutillidae,代码行数:6,代码来源:Base64Codec.php

示例3: _replaceCRLF

 /**
  * Helper function.
  *
  * Helper method to replace carriage return and line feed characters in the
  * supplied message with the supplied substitute character(s). The sequence
  * CRLF (\r\n) is treated as one character.
  *
  * @param string $message    message to process.
  * @param string $substitute Replacement for CR, LF or CRLF.
  *
  * @return string message with characters replaced.
  */
 private function _replaceCRLF($message, $substitute)
 {
     if ($message === null || $substitute === null) {
         return $message;
     }
     $detectedEncoding = Codec::detectEncoding($message);
     $len = mb_strlen($message, $detectedEncoding);
     $crlfEncoded = '';
     $nextChar = null;
     $index = 0;
     for ($i = 0; $i < $len; $i++) {
         if ($i < $index) {
             continue;
         }
         if ($nextChar === null) {
             $thisChar = mb_substr($message, $i, 1, $detectedEncoding);
         } else {
             $thisChar = $nextChar;
         }
         if ($i + 1 < $len) {
             $nextChar = mb_substr($message, $i + 1, 1, $detectedEncoding);
         } else {
             $nextChar = null;
         }
         if ($thisChar == "\r" && $nextChar == "\n") {
             $index = $i + 2;
             $nextChar = null;
             $crlfEncoded .= $substitute;
         } elseif ($thisChar == "\r" || $thisChar == "\n") {
             $crlfEncoded .= $substitute;
         } else {
             $crlfEncoded .= $thisChar;
         }
     }
     return $crlfEncoded;
 }
开发者ID:najamelan,项目名称:PHP-ESAPI,代码行数:48,代码来源:DefaultAuditor.php

示例4: encodeCharacter

 /**
  * Encodes a single character to Base64.
  *
  * @param string $immune: not used, but needs to be here to be compatible with Codec::encodeCharacter
  * @param string $input the character to encode
  *
  * @return string the base64 encoded character
  */
 public function encodeCharacter($immune = '', $c)
 {
     $detectedCharacterEncoding = Codec::detectEncoding($c);
     $c = mb_substr($c, 0, 1, $detectedCharacterEncoding);
     return $this->encode($c, false);
 }
开发者ID:najamelan,项目名称:PHP-ESAPI,代码行数:14,代码来源:Base64Codec.php


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