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

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

WBOY
Release: 2016-06-23 14:02:13
Original
904 people have browsed it

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

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

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


回复讨论(解决方案)

str_replace();用不到正则。。

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

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

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