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

关于轮换斜杠的正则,求解

WBOY
WBOYOriginal
2016-06-13 12:51:42643browse

关于替换斜杠的正则,求解。
一段字符串:D:/fff/ee//xx\eee

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

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


------解决方案--------------------
$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