Handling danish special characters [duplicate]

对着背影说爱祢 提交于 2019-12-12 02:09:29

问题


I am trying to parse a string, split it on what is not a letter or number

$parse_query_arguments = preg_split("/[^a-z0-9]+/i", 'København');

and construct a mysql query. Even if I skip the preg_split and try to enter the string directly it breaks it into 2 different strings, 'K' and 'benhavn'.

How can I deal with these issues?


回答1:


If you're using literal characters like a-z then it won't match accented ones. You might want to use the various character classes available to do more generic matching:

/[[:alpha:][:digit]]/

The [:alpha:] set is much broader in scope than a-z. Remember character matching is done based on character code, and a-z in order take, literally, characters between a and z by index. Characters like ø lie outside this range even if they'd fall between that alphabetically.

Computers work in ASCII-abetical (UNICODEical?) order.




回答2:


This might help explain what is going on in your regex... Regex and Unicode.

You could try something like \p{L} as explained in this question



来源:https://stackoverflow.com/questions/18382460/handling-danish-special-characters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!