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


PHP UtfNormal::NFKC方法代码示例

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


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

示例1: toNFKC

 /**
  * Convert a UTF-8 string to normal form KC, compatibility composition.
  * This may cause irreversible information loss, use judiciously.
  * Fast return for pure ASCII strings.
  *
  * @param $string String: a valid UTF-8 string. Input is not validated.
  * @return string a UTF-8 string in normal form KC
  */
 static function toNFKC($string)
 {
     if (NORMALIZE_INTL) {
         return normalizer_normalize($string, Normalizer::FORM_KC);
     } elseif (NORMALIZE_ICU) {
         return utf8_normalize($string, UNORM_NFKC);
     } elseif (preg_match('/[\\x80-\\xff]/', $string)) {
         return UtfNormal::NFKC($string);
     } else {
         return $string;
     }
 }
开发者ID:GodelDesign,项目名称:Godel,代码行数:20,代码来源:UtfNormal.php

示例2: foreach

     $replaced = false;
     foreach ($translation as $symbol => $character) {
         $sym_pos = strpos($buffer, $symbol);
         if ($sym_pos !== false) {
             $sym_length = strlen($symbol);
             $piece1 = substr($buffer, 0, $sym_pos);
             if ($character['switch']) {
                 // the character after the special charater needs to come before it
                 $partnerchar = utf8_encode($buffer[$sym_pos + $sym_length]);
                 $piece2 = unicode_to_utf8(array_merge(utf8_to_unicode($partnerchar), $character['unicode']));
                 $piece3start = $sym_pos + $sym_length + 1;
             } else {
                 $piece2 = unicode_to_utf8($character['unicode']);
                 $piece3start = $sym_pos + $sym_length;
             }
             $piece2 = utf8_decode(UtfNormal::NFKC($piece2));
             // strip out any ? characters, which are characters not existing in ISO-8859-1
             $piece2 = str_replace('?', '', $piece2);
             $piece3 = substr($buffer, $piece3start);
             $buffer = $piece1 . $piece2 . $piece3;
             $replaced = true;
             continue;
         }
     }
     if (!$replaced) {
         // we've encountered some character that we have no translation for
         echo "unable to find a translation to transform this buffer, the untranslatable code will be stripped out:\n{$buffer}\n";
         $pieces = preg_split('/\\$\\d*/', $buffer, 2);
         $buffer = implode('', $pieces);
     }
 }
开发者ID:BackupTheBerlios,项目名称:dilps,代码行数:31,代码来源:transformer.php


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