你不需要转换任何东西.你的要求是比较两个字符串并询问它们是否相等,忽略重音;数据库服务器可以使用
collation为您执行此操作:
Non-UCA collations have a one-to-one
mapping from character code to weight.
In MySQL, such collations are case
insensitive and accent insensitive.
utf8_general_ci is an example: ‘a’,
‘A’, ‘À’, and ‘á’ each have different
character codes but all have a weight
of 0x0041 and compare as equal.
mysql> SET NAMES 'utf8' COLLATE 'utf8_general_ci';
Query OK, 0 rows affected (0.00 sec)
mysql> SELECT 'a' = 'A', 'a' = 'À', 'a' = 'á';
+-----------+-----------+-----------+
| 'a' = 'A' | 'a' = 'À' | 'a' = 'á' |
+-----------+-----------+-----------+
| 1 | 1 | 1 |
+-----------+-----------+-----------+
1 row in set (0.06 sec)