Strip non-alphanumeric characters using PHP
You can use regular expressions to achieve this very simply.
function clean_query_string($vsString) {
return ereg_replace("[^A-Za-z0-9-]", "", $vsString);
}
The regular expression, [^A-Za-z0-9-] tells the function to replace any character that is not (^ means not) any of these characters, A-Za-z0-9-
This would be useful when you need to clean a query string value or the like.
