1. That's bad. Don't do that. The only time you should ever be using htmlspecialchars() is immediately before you're about to output something in HTML. Not any other point before then. Especially not when you're inserting it into your database.
the contents of the POST is converted to UTF-8 using htmlspecialchars($_POST['regex'], ENT_NOQUOTES, 'UTF-8');.
2. That doesn't convert encodings. All you did was tell it that it should interpret the string as if it was UTF-8. If it wasn't to begin with then it still won't be after.
var_dump(preg_match('/^[[:alnum:]]+$/u', 'Schönen Tag'));works for me as long as I make sure I put that code into a file and save it using UTF-8. If I don't then it might be ISO 8859-1 by default and I'd have to utf8_encode() (which converts from that encoding to UTF-8 ) the string first. Go to the full post