PHP. Repair Directory Path

Many times directory paths are inconsistent and containing different directory separators. For instance, "dir1/dir2\\dir3/". While most of the time using this path for referencing a directory may not be problematic, on some of the machines it may cause troubles. The following PHP snippet repairs such inconsistent paths.

$path = str_replace("\\",DIRECTORY_SEPARATOR,str_replace("/",DIRECTORY_SEPARATOR,$path));