How can I strip commas and periods from a string?

前端 未结 1 2051
青春惊慌失措
青春惊慌失措 2020-12-13 00:29

I have string containing something like this:

\"Favourite bands: coldplay, guns & roses, etc.,\"
<
相关标签:
1条回答
  • 2020-12-13 01:29

    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 讨论(0)
提交回复
热议问题