I got a little problem with a preg_replace regex. This is the code I use:
preg_replace("/[^a-zA-Z0-9_\s\/\!\,\;\?\:\.\-\"\'\§\@\&\ßäöüÄÖÜ]/", "", $string)
At the first try it works like it should but if I set all characters listed on this site as input it returns an empty string:
Á Á Á Ã Ã Ã Å Å Å À À À Â Â Â Ä Ä Ä á á á
If I remove the underscore from the regex everything is fine. Escaping it doesn't help.
I use it to filter a POST request.
Header is set like this at the top of the page from which the POST is submitted:
header('Content-type: text/html; charset=utf-8')
Whyt is wrong with the code?
It produces an error if inputted some special chars. If I remove the underscore everything is Ok.