How can I convert two or more dashes to singles and remove all dashes at the beginning and end of a string?

后端 未结 2 1975
我在风中等你
我在风中等你 2020-12-06 19:15

Example: -this--is---a-test--

What I want: this-is-a-test

Thanks for any answers! :)

2条回答
  •  醉话见心
    2020-12-06 19:41

    Without regular expression....

    $string = trim($string,'-');
    
    while (stristr($string,'--')) {$c = str_ireplace('--','-',$string);}
    

提交回复
热议问题