替换多个正斜杠

ski*_*rk1 3 php

我想用一个正斜杠替换一个以上的正斜杠。

例子:

this/is//an//example -> this/is/an/example

///another//example//// -> /another/example/

example.com///another//example//// -> example.com/another/example/

谢谢!

编辑:这将用于修复具有多个正斜杠的 URL。

diE*_*cho 5

尝试

preg_replace('#/+#','/',$str); 
Run Code Online (Sandbox Code Playgroud)

或者

preg_replace('#/{2}#','/',$str);
Run Code Online (Sandbox Code Playgroud)

小贴士:str_replace AS这样简单的替换吧

用替换字符串替换所有出现的搜索字符串

str_replace('/','/',$str);
Run Code Online (Sandbox Code Playgroud)

参考