更新时间:2021-07-01 22:31:31
我将结合使用 preg_replace
和 trim
:
I would use a combination of preg_replace
and trim
:
trim(preg_replace('/-+/', '-', $str), '-')
preg_replace
调用会删除多个破折号,而trim
会删除前导和尾随破折号.
The preg_replace
call removes multiple dashes and trim
removes the leading and trailing dashes.