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

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

WBOY
Release: 2016-06-13 11:17:34
Original
811 people have browsed it

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

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

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


------解决方案--------------------
$s = 'D:/fff/ee//xx\eee';<br />echo preg_replace('#[/\\\]+#', '/', $s);<br />
Copy after login
D:/fff/ee/xx/eee
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template