如何摆脱字符串上的非英文字母?

时间:2011-05-10 05:46:08

标签: php special-characters turkish

我想摆脱字符串中英语字符的土耳其字符,这就是我写的功能。但是,在服务器中,它不识别字母。有什么建议吗?

function strtolower_tr($string)
    {
        $low=array("Ü" => "U","ü" => "u", "Ö" => "O","ö" => "o", "Ğ" => "G","ğ" => "g", "Ş" => "S","ş" => "s", "Ç" => "C","ç" => "c", "İ" => "I","i" => "i", "I" => "i","I" => "I");
        return strtolower(strtr($string,$low));
    }

-------在服务器中-------

$low=array("?~\" => "u?", "?~V" => "o?", "?~^" => "g", "?~^" => "s", "?~G" => "c", "İ" => "i", "I" => i");

EDITED:

我发现了这个:然而,它不适用于字母'ı'和'我' setlocale(LC_ALL,'en_US.UTF8'); 功能clearUTF($ s) {          $ r ='';     $ s1 = @iconv('UTF-8','ASCII // TRANSLIT',$ s);     $ j = 0;     for($ i = 0; $ i< strlen($ s1); $ i ++){         $ ch1 = $ s1 [$ i];         $ ch2 = @mb_substr($ s,$ j ++,1,'UTF-8');         if(strstr('`^〜\''',$ ch1)!== false){             if($ ch1<> $ ch2){                  - $焦耳;                 继续;             }         }         $ r。=($ ch1 =='?')? $ ch2:$ ch1;     }     返回$ r; }

1 个答案:

答案 0 :(得分:0)

你是用utf编码的吗?您应该对源文件使用utf编码,这将解决您的问题。