我有一个包含以下内容的字符串:
"Favourite bands: coldplay, guns & roses, etc.,"
我该如何使用preg_replace
去除逗号和句号?
我有一个包含以下内容的字符串:
"Favourite bands: coldplay, guns & roses, etc.,"
我该如何使用preg_replace
去除逗号和句号?
来实现。preg_replace('/[.,]/', '', $string);
但是仅用正则表达式进行简单字符替换有些过头了。
更好的选择是使用strtr:
strtr($string, array('.' => '', ',' => ''));
或 str_replace:
str_replace(array('.', ','), '' , $string);