开发者

How can I strip commas and periods from a string?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜