Whats the best method to filter posted forms nowadays? I have only used strip in the passed by I suspect its changed alot now? I want to filter a username and other like fields. Thanks
function stripvar($string) { return preg_replace('/[^a-zA-Z0-9\s]/', '', $string); } Code (markup): How do I edit this to allow these.... @ . ? = / Code (markup):
I agree with nico_swd, dont't use regular expressions to do your filtering, as of php 5.2 there is built in filtering that you can allow certain characters and such. This is industry standard now and the day of regular expressions to filter, urls, get, post, etc.. data is long gone and not recommended, unless you have a very special circumstance.
Have I understood this right... function sanemail ($string) { $string = filter_var($string, FILTER_SANITIZE_EMAIL); return $string; } $email = "Jo^&*hn@()smi%£$th.c££om"; echo sanemail($email); Would this return "John@smith.com" ?