mysql replace accented characters

后端 未结 2 1167
攒了一身酷
攒了一身酷 2021-01-15 16:36

i would like to generate strict alphanumeric character logins from users\' first and lastname. Since many of them are foreigners, their names have special characters (é, è,

相关标签:
2条回答
  • 2021-01-15 16:52

    Here is my solution to normalize accented tags:

    REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE(  
    REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE(  
    REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE(  
    acc_tag,
    'ù','u'),'ú','u'),'û','u'),'ü','u'),'ý','y'),'ë','e'),'à','a'),'á','a'),'â','a'),'ã','a'), 
    'ä','a'),'å','a'),'æ','a'),'ç','c'),'è','e'),'é','e'),'ê','e'),'ë','e'),'ì','i'),'í','i'), 
    'î','i'),'ï','i'),'ð','o'),'ñ','n'),'ò','o'),'ó','o'),'ô','o'),'õ','o'),'ö','o'),'ø','o') AS normal_tag
    
    0 讨论(0)
  • 2021-01-15 17:02

    Well, as a French computer scientist (with an accent in his name), I would strongly advocate against such a conversion.

    Why, well, because this strategy is just replacing a wrong assumption with another wrong assumption. Let me explain myself:

    We could see the fact that only us-ascii are allowed in login id as an incorrect assumption that "all user names can be written in ascii".

    Trying to remove accents from users name is just replacing the assumption by "all user names can be converted to ascii".

    That is also incorrect: It will work for me (as a European - Latin 1 proof named person), but how will you compute the name of 三島 ? or the one of Сахаров ?

    I know my answer is non technical, but you should do whatever is necessary to allow non ascii chars in logins. Or, you should allow your users to choose this login.

    0 讨论(0)
提交回复
热议问题