Get parts of a URL path

@param string $url
@return array
760777
protected function splitUrl($url)
    {
        $path = parse_url(trim($url, '/'), PHP_URL_PATH);
        return $path ? explode('/', $path) : array();
    }
541711
protected function getDomainRoots( $url ) {
		$roots = [];
		$pieces = parse_url( $url );
		if ( !isset( $pieces['host'], $pieces['host'] ) ) {
			return [];
		}
		$roots[] = $pieces['host'];
		$roots[] = $pieces['host'] . '/';
		$domain = isset( $pieces['host'] ) ? $pieces['host'] : '';
		if ( preg_match( '/(?P<domain>[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i', $domain, $regs ) ) {
			$roots[] = $regs['domain'];
			$roots[] = $regs['domain'] . '/';
		}
		$parts = explode( '.', $pieces['host'] );
		if ( count( $parts ) >= 3 ) {
			$roots[] = implode( '.', array_slice( $parts, -2 ) );
			$roots[] = implode( '.', array_slice( $parts, -2 ) ) . '/';
		}

		return $roots;
	}
811971
public function parse(Url $url) :? array
	{
		// Get path without possible file
		$path = $url->path();

		// Build route pattern
		$pattern = $this->buildRoutePattern();

		if (preg_match($pattern, $path, $matches) === 1) {

			$variables = [];
			$length = sizeof($matches);

			for ($i = 1; $i < $length; $i++) {
				$variables[$this->parameter[$i - 1]] = $matches[$i];
			}

			return $variables;
		}

		return null;
	}
100533
protected function _parseExtension($url)
    {
        if (count($this->_extensions) && strpos($url, '.') !== false) {
            foreach ($this->_extensions as $ext) {
                $len = strlen($ext) + 1;
                if (substr($url, -$len) === '.' . $ext) {
                    return [substr($url, 0, $len * -1), $ext];
                }
            }
        }

        return [$url, null];
    }
545860
public static function getParamsAsArray($url)
    {
        $query = parse_url($url, PHP_URL_QUERY);
        if (!$query) {
            return [];
        }
        $params = [];
        parse_str($query, $params);

        return $params;
    }
378351
public static function url_to_file_system( $url ) {
		$url_parts = parse_url($url);
		$url_parts['path'] = apply_filters('timber/URLHelper/url_to_file_system/path', $url_parts['path']);
		$path = ABSPATH.$url_parts['path'];
		$path = str_replace('//', '/', $path);
		return $path;
	}
717076
public static function parseUrl($url)
    {
        $parseUrlResult = parse_url($url);
        if ($parseUrlResult === false) {
            return false;
        }

        if (empty($parseUrlResult['scheme'])) {
            $parseUrlResult['scheme'] = 'http';
        }

        if (empty($parseUrlResult['host'])) {
            return false;
        }

        $parseUrlResult['url'] = $url;

        if (empty($parseUrlResult['port'])) {
            if ($parseUrlResult['scheme'] == 'http') {
                $parseUrlResult['port'] = 80;
                $parseUrlResult['ssl']  = false;
            } else {
                $parseUrlResult['port'] = 443;
                $parseUrlResult['ssl']  = true;
            }
        } else {
            if ($parseUrlResult['scheme'] == 'http') {
                $parseUrlResult['ssl']  = false;
            } else {
                $parseUrlResult['ssl']  = true;
            }
        }

        if (empty($parseUrlResult['path'])) {
            $parseUrlResult['path'] = '/';
        }

        if (empty($parseUrlResult['query'])) {
            $parseUrlResult['query'] = '';
        } else {
            $parseUrlResult['query'] = '?' . $parseUrlResult['query'];
        }

        return $parseUrlResult;
    }
319092
private function getUriHostAndPath($url)
    {
        try {
            $uri = HttpUri::createFromString($url);
        } catch (InvalidArgumentException $e) {
            return ['', ''];
        }

        $host = $uri->getHost();
        $port = $uri->getPort();
        if (!$port && $uri->getScheme() == 'https') {
            $port = 443;
        }
        if ($port) {
            $host .= ':'.strval($port);
        }
        $path = $uri->getPath();
        if (!$path) {
            $path = '/';
        }

        return [$host, $path];
    }
502252
protected function parseUrl($url = "")
    {
        $parsed = ($url) ? parse_url($url) : parse_url($this->_env['REQUEST_URI']);
        
        if (preg_match('/[a-zA-Z0-9_]+\.php/i', $parsed['path'], $matches)) {
            $parsed['path'] = preg_replace("/$matches[0]/", '/', $parsed['path']);
        }
        
        return $parsed;
    }
347777
public static function getDomainFromURL($url)
	{
		$url = str_replace(self::getProtocolFromURL($url) . '://', '', $url);
		
		return explode('/', $url)[0];
	}
981514
public function parseUrl($url)
    {
        $scheme   = parse_url($url, PHP_URL_SCHEME);
        $domain   = parse_url($url, PHP_URL_HOST);
        $basename = pathinfo($url, PATHINFO_BASENAME);

        $parts = explode('.', $basename);

        if(count($parts) == 3)
        {
            $type  =  array_pop($parts);
            $format = array_pop($parts);
            $file   = array_pop($parts);
        }
        else
        {
            $type   = '*';
            $format = array_pop($parts);
            $file   = array_pop($parts);
        }

        $path = str_replace(array($scheme.'://', $scheme.':'), '', dirname($url));

        if (strpos($path, $domain.'/') === 0) {
            $path = substr($path, strlen($domain)+1);
        }

        $parts = explode('/', $path);

        $info = array(
            'type'    => $type,
            'domain'  => $domain,
            'package' => array_shift($parts),
            'path'    => implode('/', $parts),
            'file'    => $file,
            'format'  => $format ?: '*',
        );

        return $info;
    }
729114
private function match(string $url): ?array
    {
        $path = \trim(\explode('?', $url, 2)[0], self::SEPARATOR_TRIM);

        $key = $this->prefix . '_' . $path;
        $result = self::optimizeGet($key);
        if (!empty($result)) {
            return $result;
        }

        $parts = \explode('/', $path);
        if (!isset($parts[1]) && $parts[0] === '') {
            $parts = [];
        }

        $params = [];
        $current = $this->routes;
        foreach ($parts as $v) {
            if (isset($current['children'][$v])) {
                $current = $current['children'][$v];
                continue;
            }

            if ($current['regexps'] !== []) {
                foreach ($current['regexps'] as $regexp => $route) {
                    if (\preg_match($regexp, $v)) {
                        $current = $route;
                        $params[$current['name']] = $v;
                        continue 2;
                    }
                }
            }

            if (!isset($current['others'])) {
                return null;
            }

            $current = $current['others'];
            $params[$current['name']] = $v;
        }

        $result = [
            'methods' => $current['methods'],
            'route' => $current['route'],
            'params' => $params,
        ];

        self::optimizeSet($key, $result);

        return $result;
    }
830977
public function extractShortUrl(string $url):array {
		$urls = [$url];

		while($url = $this->extract($url)){
			$urls[] = $url;
		}

		return $urls;
	}
960775
protected function processRoutes($url)
    {
        $routes = $this->config->get('routes', []);

        foreach ($routes as $from => $to) {
            $result = UrlHelper::routeParse($from, $to, $url);
            if (false !== $result && (empty($result->methods) || in_array($this->method, $result->methods, true))) {
                return $result->url;
            }
        }

        return $url;
    }
819081
public function extractPath($url)
    {
        $parts = $this->parseUrl($url);

        if (!isset($parts['path'])) {
            return null;
        }
        // ignore non-http schemes
        if (isset($parts['scheme']) && !in_array($parts['scheme'], ['http', 'https'])) {
            return null;
        }

        return $parts['path'];
    }
911962
public function getRoutePath($url = "") {
        if (isset($_SERVER['REDIRECT_QUERY_STRING']) && empty($url)) {
            $url = $_SERVER['REDIRECT_QUERY_STRING'];
        }
        if (isset($_SERVER['REQUEST_URI']) && empty($url)) {
            $url = $_SERVER['REQUEST_URI'];
        }
        if (isset($_SERVER['PATH_INFO']) && empty($url)) {
            $url = $_SERVER['PATH_INFO'];
        }
        return explode('/', trim($url, '/'));
    }
845645
public static function getPath($url)
    {
        $matchFound = preg_match('/(\/v[23]\/.*$)/', $url, $matches);
        if( ! $matchFound || ! is_array($matches) || ! isset($matches[1])) {
            throw new \Exception('Unable to parse url path', 1462733286);
        }

        return $matches[1];
    }