I have string containing something like t开发者_如何学Pythonhis:
"Favourite bands: coldplay, guns & roses, etc.,"
How can I remove commas and periods using preg_replace
?
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);
精彩评论