tags:

views:

52

answers:

2

What would be a good way to get rid of all chars except, letters, numbers, double quotes and hyphens. This is what I got so far.

$test = preg_replace('#[^a-zA-Z0-9"-]#',' ',$string);

Any suggestions?

Thanks

+3  A: 

Your regex is about as good a solution as you are going to find.

Andrew Hare
+2  A: 

You can use \d to match digits, and the flag i to match a-z with case insensitivity.

$test = preg_replace('#[^a-z\d\w"-]#i','',$string);

Here is the php regex-syntax reference: http://se.php.net/manual/en/regexp.reference.php

PatrikAkerstrand
Correct me if I'm wrong, but doesn't \w also match numbers?
musicfreak
This is incorrect as \w matches underscores.
Jeremy Stein