當前位置: 首頁>>代碼示例>>PHP>>正文


PHP UTF8::to_ascii方法代碼示例

本文整理匯總了PHP中UTF8::to_ascii方法的典型用法代碼示例。如果您正苦於以下問題:PHP UTF8::to_ascii方法的具體用法?PHP UTF8::to_ascii怎麽用?PHP UTF8::to_ascii使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在UTF8的用法示例。


在下文中一共展示了UTF8::to_ascii方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: downcode

 /**
  * Transliterates characters to their ASCII equivalents.
  * $language specifies a priority for a specific language.
  * The latter is useful if languages have different rules for the same character.
  *
  * @param string  $string                            <p>The input string.</p>
  * @param string  $language                          <p>Your primary language.</p>
  * @param boolean $convertToAsciiOnlyViaLanguageMaps <p>
  *                                                   Set to <strong>true</strong> if you only want to convert the
  *                                                   language-maps.
  *                                                   (better performance, but less complete ASCII converting)
  *                                                   </p>
  * @param boolean $convertUtf8Specials               <p>
  *                                                   Convert (html) special chars with portable-utf8 (e.g. \0,
  *                                                   \xE9, %F6, ...).
  *                                                   </p>
  * @param string  $unknown                           <p>Character use if character unknown. (default is ?).</p>
  *
  * @return string
  */
 public static function downcode($string, $language = 'de', $convertToAsciiOnlyViaLanguageMaps = false, $unknown = '', $convertUtf8Specials = true)
 {
     self::init_downcode($language);
     if ($convertUtf8Specials === true) {
         $string = UTF8::urldecode($string);
     }
     $searchArray = array();
     $replaceArray = array();
     if (preg_match_all(self::$regex, $string, $matches)) {
         $matchesCounter = count($matches[0]);
         /** @noinspection ForeachInvariantsInspection */
         for ($i = 0; $i < $matchesCounter; $i++) {
             $char = $matches[0][$i];
             if (isset(self::$map[$char])) {
                 $searchArray[] = $char;
                 $replaceArray[] = self::$map[$char];
             }
         }
     }
     $string = str_replace($searchArray, $replaceArray, $string);
     if ($convertToAsciiOnlyViaLanguageMaps === true) {
         return (string) $string;
     }
     return UTF8::to_ascii($string, $unknown);
 }
開發者ID:voku,項目名稱:urlify,代碼行數:45,代碼來源:URLify.php


注:本文中的UTF8::to_ascii方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。