Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

preg_replace returns NULL

$
0
0
Hi,

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:

http://www.tamingthebeast.net/articles2/special-characters.htm

Short Snippet
Á 	Á 	Á
à 	à 	Ã
Å 	Å 	Å
À 	À 	À
 	 	Â
Ä 	Ä 	Ä
á 	á 	á



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?

Summary:

It produces an error if inputted some special chars. If I remove the underscore everything is Ok.

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>