php regex to replace 'any' slashes in a path with directory separator

前端 未结 4 2078
陌清茗
陌清茗 2021-01-14 12:40

I am trying to take paths like this:

some/path/here some\\other\\path

and replace each slash in the paths with PHP\'s DIRECTORY_SEPARATOR built in constant

4条回答
  •  臣服心动
    2021-01-14 13:14

    It should replace, not add. But try this:

    preg_replace('/[\\]/', DS, $subject);
    

    Should also work.

提交回复
热议问题