Convert "Fancy" unicode ABC to standard ABC

Viewed 162

I run Regex checks on certain inputs on my site, but the Regex wrongfully returns false when users use "Fancy" Unicode sets such as:

Ⓜⓐⓣⓒⓗ Match ⒨⒜⒯⒞⒣

These are not different fonts, they are different characters! None of these are matched by /Match/ (Proof)

How can I convert the user input to standard ABC characters before running through my Regex checks? (I'm using PHP, if that makes a difference)

1 Answers

The NFKD unicode normalisation should take care of most of those. However, it seems it only works if intl module is enabled, and I don't have it in my environment, so I can't test it. If you also don't have such a PHP, and don't want to install it, this does something a bit similar, at least for some of the characters:

iconv("UTF-8", "ISO-8859-1//TRANSLIT", $text)

Finally, you can make your own mapping, for example using strtr (which you will then know to work, since you'd've written it yourself).

Related