Normalize path
Normalizes the slashes in an path
Author:
Jonas John
License:
Public Domain
Language:
PHP
Created:
03/28/2006
Updated:
03/28/2006
Tags:
directory functions, folder, files
// todo: file support, maybe add dirname() function normalize_path($path){ // DIRECTORY_SEPARATOR is a system variable // which contains the right slash for the current // system (windows = \ or linux = /) $s = DIRECTORY_SEPARATOR; $path = preg_replace('/[\/\\\]/', $s, $path); $path = preg_replace('/'.$s.'$/', '', $path) . $s; return $path; }
on windows:<br/>normalize_path('/go/foo/bar'); --> returns \go\foo\bar\