tags:

views:

29

answers:

1

Hi, i want to delete all characters except a-zA-Z0-9 and _ chracter. How can do that in php ?

+1  A: 
preg_replace("/[^a-zA-Z0-9_]/","",$string); 

Or

preg_replace("/[^a-z0-9_]/i","",$string);

Or

preg_replace("/[^[:alpha:][:digit:]_]/","",$string)
ghostdog74
Can't `[^a-zA-Z0-9_]` be shortened to `\W`?
Amarghosh
sure, yes it can.
ghostdog74