8

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.

Community
  • 1
  • 1
Andresch Serj
  • 35,217
  • 15
  • 59
  • 101
  • Answer is: echo iconv('UTF-8', 'ASCII//TRANSLIT', $string); – Palantir Jul 28 '11 at 09:40
  • Oh, i didn't find that duplicate answer. What is the policy? Do i delete my question now or link to the other question? – Andresch Serj Jul 28 '11 at 09:45
  • 1
    Welcome to Stack Overflow. This question is already linked to the other question and if enough moderators (five) vote to close it, it will be automatically closed as duplicate. I guess you don't need to do anything special now. – Palantir Jul 28 '11 at 09:49
  • 1
    I laughed when I saw this question, because I nearly posted the same exact question myself a few days ago, after having read every similar question without satisfying result. I found the answer I posted below through some more googling and trial+error. It might be useful to someone :) – designosis Jul 28 '11 at 09:53
  • @neokio Since this question is very likely to be closed soon, would you mind to reply to the OTHER question, so the next one who searches for this can enjoy your contribution too? Otherwise it will be lost... – Palantir Jul 28 '11 at 09:55

1 Answers1

15

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');
    }
designosis
  • 5,182
  • 1
  • 38
  • 57