开发者

Convert special character (i.e. Umlaut) to most likely representation in ascii [duplicate]

开发者 https://www.devze.com 2023-03-23 17:30 出处:网络
This question already has answers here: 开发者_如何学运维 PHP: Replace umlauts with closest 7-bit ASCII equivalent in an UTF-8 string
This question already has answers here: 开发者_如何学运维 PHP: Replace umlauts with closest 7-bit ASCII equivalent in an UTF-8 string (7 answers) Closed 9 years ago.

i am looking for a method or maybe a conversion table that knows how to convert Umlauts and special characters to their most likely representation in ascii.

Example:

Ärger = aerger
Bôhme = bohme
Søren = soeren
pjérà = pjera

Anyone any idea?

Update: Apart from the good accepted Answer, i also found PECLs Normalizer to be quite interesting, though i can not use it due to the server not having it and not being changed for me.

Also do check out this Question if the Answers here do not help you enough.


I find iconv completely unreliable, and I dislike preg_match solutions and big arrays ... so my favorite way is ...

    function toASCII( $str )
    {
        return strtr(utf8_decode($str), 
            utf8_decode('ŠŒŽšœžŸ¥µÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿ'),
            'SOZsozYYuAAAAAAACEEEEIIIIDNOOOOOOUUUUYsaaaaaaaceeeeiiiionoooooouuuuyy');
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号