I'm trying to clean up a string.
I need to only allow
_-+*()[]!#?.,;:'"<>Everything else needs to go bye-bye. How do I go about this? I have this, which works for the upper/lower case letters, numbers, and spaces. But I dont know how to account for the tabs, carriage returns, or how to do the special characters?
$str = preg_replace('/[^a-z0-9 ]/i', '', $str);
Try
$str = preg_replace('/[^\w\r\n\t+*()[\]!#?.\,;:\'"<> -]/', '', $str);
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