开发者

How can I strip commas and periods from a string?

开发者 https://www.devze.com 2023-01-31 15:57 出处:网络
I have string containing something like t开发者_如何学Pythonhis: \"Favourite bands: coldplay, guns & roses, etc.,\"

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号