URLify::downcode PHP Method

downcode() public static method

$language specifies a priority for a specific language. The latter is useful if languages have different rules for the same character.
public static downcode ( $text, $language = "" )
    public static function downcode($text, $language = "")
    {
        self::init($language);
        if (preg_match_all(self::$regex, $text, $matches)) {
            for ($i = 0; $i < count($matches[0]); $i++) {
                $char = $matches[0][$i];
                if (isset(self::$map[$char])) {
                    $text = str_replace($char, self::$map[$char], $text);
                }
            }
        }
        return $text;
    }

Usage Example

示例#1
0
 /** Takes text and converts it to an ASCII-only string (characters with code between 32 and 127, plus \t, \n and \r).
  * @param string $text The text to be converted.
  * @param string $locale='' The locale for the string. If not specified we consider the current locale.
  * @return string
  */
 public function asciify($text, $locale = '')
 {
     if (!strlen($locale)) {
         $locale = \Localization::activeLocale();
     }
     $language = substr($locale, 0, strcspn($locale, '_'));
     $text = \URLify::downcode($text, $language);
     if (preg_match('/[^\\t\\r\\n\\x20-\\x7e]/', $text)) {
         if (function_exists('iconv')) {
             $t = @iconv(APP_CHARSET, 'US-ASCII//IGNORE//TRANSLIT', $text);
             if (is_string($t)) {
                 $text = $t;
             }
         }
         $text = preg_replace('/[^\\t\\r\\n\\x20-\\x7e]/', '', $text);
     }
     return $text;
 }
All Usage Examples Of URLify::downcode