Valid characters include the alphabet (abcd..), numbers (0123456789), spaces, ' and ".
I need to strip any other characters than these from a string in PHP.
Thanks :)
You can do this:
$str = preg_replace('/[^a-z0-9 "\']/', '', $str);
Here the character class [^a-z0-9 "']
will match any character except the listed ones (note the inverting ^
at the begin of the character class) that are then replaced by an empty string.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With