public static function fixPath($path) { $path = str_replace('\\', '/', $path); //windows paths $replace = ['#(/\\.?/)#', '#/(?!\\.\\.)[^/]+/\\.\\./#']; do { $path = preg_replace($replace, '/', $path, -1, $n); } while ($n > 0); return $path; }