Extract host value from url

@param string $url

@return string
191996
public function extract_host( $url ) {
		$string = (string) $url;
		if ( preg_match( '@https?://([^/\?#]+)@u', $url, $match ) ) {
			return $match[1];
		} else {
			return $url;
		}
	}
1312558
public function parseUrl($url) {
		$url = parse_url($url);
		$url['vars'] = array();
		if (!isset($url['fragment'])) {
			$url['fragment'] = null;
		}
		if (isset($url['query'])) {
			parse_str($url['query'], $url['vars']);
		}

		return $url;
	}
712364
private static function cleanUrl($url)
    {
        $result = '';
        $inner = false;

        for ($i = 0; $i < strlen($url); $i++) {
            if (!$inner) {
                if ($url[$i] != '{') {
                    $result .= $url[$i];
                } else {
                    $result .= '{';
                    $inner = true;
                }
            } else {
                if ($url[$i] == '}') {
                    $result .= '}';
                    $inner = false;
                }
            }
        }

        return $result;
    }
81774
private function getUrl(string $url): string
    {
        $urlParts = parse_url($url);

        if ($urlParts === false) {
            throw new \ParseError("Could not parse URL: $url");
        }

        if ($this->baseUrl !== null && ! isset($urlParts['host'])) {
            $url = $this->baseUrl . '/' . ltrim($url, '/');
        }

        return $url;
    }
891944
public function getExposedPath($url)
    {
        $isExposedAs = '';
        list($host, $path) = $this->getUriHostAndPath($url);

        if ($host == $this->host) {
            foreach ($this->paths as $exposedPath => $exposedDirectory) {
                $relative = $this->getRelative($path, $exposedPath);
                if (!is_null($relative)) {
                    $isExposedAs = $exposedDirectory.$relative;
                    break;
                }
            }
        }

        return $isExposedAs;
    }
1031516
public static function parse_url( $url ) {
		$r             = wp_parse_url( $url );
		$r['pathname'] = empty( $r['path'] ) ? '/' : $r['path'];
		return $r;
	}
915711
public static function getHostname($url)
    {
        if (!isset(self::$cache[$url]['hostname'])) {
            self::$cache[$url]['hostname'] = self::parseUrl($url, PHP_URL_HOST);
        }

        return self::$cache[$url]['hostname'];
    }
848710
public static function getHostFromUrl($url)
    {
        $parsedUrl = parse_url($url);

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

        return Common::mb_strtolower($parsedUrl['host']);
    }
540478
protected function getUrlContents(string $url): string
    {
        $request = $this->getRequest($url);

        return $this->getParsedResponse($request);
    }
129105
public function getHost(string $host)
	{
		$host = Host::filter($host);
		return $this->offsetExists($host) ? $this->hosts[$host] : null;
	}
69522
private function extractHost($url)
    {
        $urlParts = parse_url($url);
        if (isset($urlParts['host']) && strlen($host = $urlParts['host'])) {
            return $host;
        }

        return false;
    }
747868
protected function rewriteUrl($url)
    {
        if (empty($this->hosts)) {
            return $url;
        }

        $randKey = array_rand($this->hosts, 1);

        // BC
        if (is_numeric($randKey)) {
            $host = parse_url($url, PHP_URL_SCHEME).'://'.parse_url($url, PHP_URL_HOST);
            $proxyHost = $this->hosts[$randKey];

            return str_replace($host, $proxyHost, $url);
        }

        if (0 === mb_strpos($randKey, 'regexp/')) {
            $regExp = mb_substr($randKey, 6);

            return preg_replace($regExp, $this->hosts[$randKey], $url);
        }

        return str_replace($randKey, $this->hosts[$randKey], $url);
    }
881303
protected function getWebPage($url)
    {
        $curl = curl_init();

        curl_setopt($curl, CURLOPT_URL,            $url);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_HEADER,         false);
        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
        $output = curl_exec($curl);
        curl_close($curl);

        return (string) $output;
    }
894718
public function fetchUrl($url)
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

        // HTTPS
        if (strpos($url, 'https://') !== false) {
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        }

        $res = curl_exec($ch);
        curl_close($ch);

        return $res;
    }
679241
private function cleanUrl($url)
    {
        if (strlen($url) > 1 && strrpos($url, '/') === strlen($url) - 1) {
            $url = substr($url, 0, -1);
        }
        if (strrpos($url, '.php') === strlen($url) - 4) {
            $url = substr($url, 0, -4);
        }
        return $url;
    }
1099712
public function urlQuerystring($url)
    {
        $querystring = $this->querystring();
        if (isset($this->timestamp) && !Utils::contains($querystring, $this->timestamp)) {
            $querystring = empty($querystring) ? ('?' . $this->timestamp) : ($querystring . '&' . $this->timestamp);
        }

        return ltrim($url . $querystring . $this->urlHash(), '/');
    }
848433
static public function parseUrl($url)
    {
        $urlArr = parse_url($url);

        if (array_key_exists('scheme', $urlArr) && !array_key_exists('port', $urlArr)) {
            switch ($urlArr['scheme']) {
                case 'http':
                    $urlArr['port'] = 80;
                    break;
                case 'https':
                    $urlArr['port'] = 443;
                    break;
            }
        }

        return $urlArr;
    }