Reputation: 35
I've came across this function that will do the first part I think
preg_replace("/[^A-Za-z0-9 ]/", '', $string);
But I don't want to remove '-','+' or '|'. How can I make exceptions for these.
Upvotes: 0
Views: 105
Reputation: 10717
Add with \char
preg_replace("/[^A-Za-z0-9 \-\+\|]/", '', $string);
Demo: http://regexr.com?35lre
Upvotes: 0
Reputation: 13535
You can also use the short form with \w
preg_replace("/[^\w\+\|\-\s]/", '', $string);
Upvotes: 2
Reputation: 32740
Try this :
$string = "abcdAbcd-0999345@dfsdf%+";
echo preg_replace("/[^A-Za-z0-9\+\-\| ]/", '', $string);
Upvotes: 0