tags:

views:

339

answers:

2

I need to remove all characters from a string which aren't a-z A-Z 0-9 or " ", anyone got a function to do this?

+11  A: 

Sounds like you almost knew what you wanted to do already, you basically defined it as a regex.

preg_replace("/[^A-Za-z0-9 ]/", '', $string);
Chad Birch
I know but I suck foot at RegEx, thanks dude!
zuk1
+1  A: 

Regular expression is your answer.

$str = preg_replace('/[^a-z\d ]/i', '', $str);
raspi