开发者

mysql replace accented characters

开发者 https://www.devze.com 2022-12-28 16:49 出处:网络
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 (é, è, ï, ...). I would like to

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 (é, è, ï, ...). I would like to remove the accents (e,e,i,...) in the logins.

Here is my query. Is there a character set开发者_如何学C that does not contain accents?

UPDATE contacts SET login=CONVERT(LOWER(CONCAT(firstname,'.',lastname)) USING utf8);


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


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

精彩评论

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