Reputation: 1295
I have string containing something like this:
"Favourite bands: coldplay, guns & roses, etc.,"
How can I remove commas and periods using preg_replace
?
Upvotes: 34
Views: 68591
Reputation: 239240
You could use
preg_replace('/[.,]/', '', $string);
but using a regular expression for simple character substitution is overkill.
You'd be better off using strtr:
strtr($string, array('.' => '', ',' => ''));
or str_replace:
str_replace(array('.', ','), '' , $string);
Upvotes: 131