code: public function normalizePath($path)
      {
          $parts = array();
          $path = strtr($path, '\\', '/');
          $prefix = '';
          $absolute = false;
  
          // extract a prefix being a protocol://, protocol:, protocol://drive: or simply drive:
          if (preg_match('{^( [0-9a-z]{2,}+: (?: // (?: [a-z]: )? )? | [a-z]: )}ix', $path, $match)) {
              $prefix = $match[1];
              $path = substr($path, strlen($prefix));
          }
  
          if (substr($path, 0, 1) === '/') {
              $absolute = true;
              $path = substr($path, 1);
          }
  
          $up = false;
          foreach (explode('/', $path) as $chunk) {
              if ('..' === $chunk && ($absolute || $up)) {
                  array_pop($parts);
                  $up = !(empty($parts) || '..' === end($parts));
              } elseif ('.' !== $chunk && '' !== $chunk) {
                  $parts[] = $chunk;
                  $up = '..' !== $chunk;
              }
          }
  
          return $prefix.($absolute ? '/' : '').implode('/', $parts);
      }
docs: Normalize a path. This replaces backslashes with slashes, removes ending
  slash and collapses redundant separators and up-level references.
  
  @param  string $path Path to the file or directory
  @return string