0

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?

Potney Switters
  • 2,902
  • 4
  • 33
  • 51
  • Use a different character set... like `utf-8` ... [UTF-8 all the way through](http://stackoverflow.com/questions/279170/utf-8-all-the-way-through) – naththedeveloper Aug 22 '13 at 14:10

2 Answers2

2

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.

tadman
  • 208,517
  • 23
  • 234
  • 262
1

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

Community
  • 1
  • 1
gargantuan
  • 8,888
  • 16
  • 67
  • 108