我想用一个正斜杠替换多个正斜杠。
例子:
this/is//an//example
-> this/is/an/example
///another//example////
-> /another/example/
example.com///another//example////
-> example.com/another/example/
谢谢!
编辑:这将用于修复具有多个正斜杠的 URL。
最佳答案
试试
preg_replace('#/+#','/',$str);
或
preg_replace('#/{2}#','/',$str);
提示:使用str_replace
对于这样一个简单的替换它
replace all occurrences of the search string with the replacement string
str_replace('/','/',$str);
关于php - 替换多个正斜杠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8631017/