pepebe
8/29/2013 - 12:05 PM

Some functions to normalize path information

Some functions to normalize path information

/*
Some useful functions to normalize path information
Source: http://forums.modx.com/thread/85485/restarting-phpthumbof-development?page=2#dis-post-476108
*/

/* delete trailing slash */
$dir = rtrim('/\\', $dir);
 
/* delete leading slash */
$dir = ltrim('/\\', $dir);
 
/* delete both */
$dir = trim('/\\', $dir);
 
/* Add back when appropriate */
$path = $dir . '/' . $path;
 
/* Remove double slashes */
$path = str_replace('//', '/', $path);
$path = str_replace('\\\\', '\\');

/* Also useful... */
function normalize($path) {
        return strtolower(str_replace("\\", '/', $path));
}