PHP replace all spaces with hyphens

前端 未结 1 526
我寻月下人不归
我寻月下人不归 2020-12-19 12:04

I replace all spaces with hyphens in my script like this:

$final = str_replace(\' \',\'-\',$final); The - is the only thing I replace.

What

相关标签:
1条回答
  • 2020-12-19 12:32

    Use a regular expression changing multiple spaces or hyphens with one hyphen:

    $final = preg_replace('#[ -]+#', '-', $text);
    
    0 讨论(0)
提交回复
热议问题