Home  >  Article  >  Backend Development  >  关于替换斜杠的正则,求解。

关于替换斜杠的正则,求解。

WBOY
WBOYOriginal
2016-06-23 14:02:13788browse

一段字符串:D:/fff/ee//xx\eee

想得到的结果是:D:/fff/ee/xx/eee

大于等于两个斜杠的时候,替换为一个斜杠。
当有反斜杠的时候,替换为正斜杠。


回复讨论(解决方案)

str_replace();用不到正则。。

str_replace();用不到正则。。
就是要在用正则的情况下 应该怎么写。

$s = 'D:/fff/ee//xx\eee';echo preg_replace('#[/\\\]+#', '/', $s);
D:/fff/ee/xx/eee

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn