With a PHP function I’m trying to create a RegEx string for preg_replace that will only allow alphanumeric characters plus ! @ # $ % & . ,
The PHP function is
function clean($var) {
$regEx="REGEXSTRING";
$var = preg_replace($regEx, "", $var);
return str_replace(array("&", "'"),
array("&", "'"), $var);
}
What would the string be to match what I’m looking for.
:: EDIT :: As I was typing this I figured out what would work for me. Not sure if it is the best solution but it works. But I figured I’d post it here as a solution for other beginners.
The string I used is…
$regEx="/[^a-zA-Z0-9 !@#$%&.,]/";
Hope it helps someone.
1 Answer