public static function normalizePath($path, $rtrim = true){
		$path = trim($path);
		// replace every back slash with forward slash
		$path = str_replace('\\', '/', $path);
		// replace all double slashes with single
		$path  = preg_replace( '/\/+/', '==DS==', $path );
		// trim slashes on begining
		$segments = explode('==DS==', $path);
		$path = implode(DIRECTORY_SEPARATOR, $segments);
		//$path = ltrim($path, DIRECTORY_SEPARATOR);

		if($rtrim){
			$path = rtrim($path, DIRECTORY_SEPARATOR);
		}

		return $path;
	}
public static function normalizePath($path, $rtrim = true){
		$path = trim($path);
		// replace every back slash with forward slash
		$path = str_replace('\\', '/', $path);
		// replace all double slashes with single
		$path  = preg_replace( '/\/+/', '==DS==', $path );
		// trim slashes on begining
		$segments = explode('==DS==', $path);
		$path = implode(DIRECTORY_SEPARATOR, $segments);
		//$path = ltrim($path, DIRECTORY_SEPARATOR);

		if($rtrim){
			$path = rtrim($path, DIRECTORY_SEPARATOR);
		}

		return $path;
	}
public static function normalizePath ( $ path , $ rtrim = true ) { $ path = trim ( $ path ) ; // replace every back slash with forward slash $ path = str_replace ( '\\' , '/' , $ path ) ; // replace all double slashes with single $ path = preg_replace ( '/\/+/' , '==DS==' , $ path ) ; // trim slashes on begining $ segments = explode ( '==DS==' , $ path ) ; $ path = implode ( DIRECTORY_SEPARATOR , $ segments ) ; //$path = ltrim($path, DIRECTORY_SEPARATOR); if ( $ rtrim ) { $ path = rtrim ( $ path , DIRECTORY_SEPARATOR ) ; } return $ path ; }
Normalizes path slashes when mixed between path and url conversion

It takes string with mixed or doubled slashes and converts them
to single slashes dependent on system beacose of use of DIRECTORY_SEPARATOR const,
and optionally trims right slash.

There are two parameters,
string that will be normalized and optional rtrim flag

@param string $path - string to be normalized
@param boolean $rtrim - flag for right trim option
@return string normalized path.
Normalizes path slashes when mixed between path and url conversion