Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 921
Andresch Serj Avatar asked Jul 28 '11 09:07

Andresch Serj


1 Answers

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');
    }
like image 121
neokio Avatar answered Sep 30 '22 11:09

neokio