Normalize path

Normalizes the slashes in an path

Snippet information

Author:
Jonas John

License:
Public Domain

Language:
PHP

Created:
03/28/2006

Updated:
03/28/2006

Tags:
, ,


// 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;
}


Found a bug? Or do you have a better solution for this?
Feel free to leave a message:

Add a comment


Leave a comment