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>
If you don't explicitly need regex, then this is the way:
$string = "some/path/here some\other\path"; $ds = DIRECTORY_SEPARATOR; $result = str_replace(array("/","\\"),$ds,$string); echo $result;
Outputs: some/path/here some/other/path