Return search engine host in URL

@param string $url
@return string host
422970
private function getHostFromUrl($url)
    {
        if (strpos($url, '//')) {
            $url = substr($url, strpos($url, '//') + 2);
        }
        if (($p = strpos($url, '/')) !== false) {
            $url = substr($url, 0, $p);
        }
        return $url;
    }
347777
public static function getDomainFromURL($url)
	{
		$url = str_replace(self::getProtocolFromURL($url) . '://', '', $url);
		
		return explode('/', $url)[0];
	}
21711
private function getUrl($url)
    {
        // Check for URL scheme
        if (parse_url($url, PHP_URL_SCHEME) === null) {
            $url = Arr::get($this->config, 'base_uri') . $url;
        }

        return $url;
    }
20084
public static function base($url) {
        if (preg_match('#^(/|(ht|f)tps?://).+#', $url)) {
            return $url;
        }
        $url = preg_replace('#/?index\.html?$#', '', $url);

        return WWWROOT_DIR . $url;
    }
279701
private function getPath($url)
    {
        $url = trim($url);
        $parsed = $this->parseURL($url);
        if ($parsed !== false) {
            $this->url = $url;
            return $parsed['custom'];
        }
        return $url;
    }
675200
public static function getHeaderFromUrl($url) {
		// @codingStandardsIgnoreStart
		$url = @parse_url($url);
		// @codingStandardsIgnoreEnd
		if (empty($url)) {
			return false;
		}

		$url = array_map('trim', $url);
		$url['port'] = (!isset($url['port'])) ? '' : (':' . (int)$url['port']);
		$path = (isset($url['path'])) ? $url['path'] : '';

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

		$path .= (isset($url['query'])) ? "?$url[query]" : '';

		$defaults = [
			'http' => [
				'header' => "Accept: text/html\r\n" .
					"Connection: Close\r\n" .
					"User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64)\r\n",
			]
		];
		stream_context_get_default($defaults);

		if (isset($url['host']) && $url['host'] !== gethostbyname($url['host'])) {
			$url = "$url[scheme]://$url[host]$url[port]$path";
			$headers = get_headers($url);
			if (is_array($headers)) {
				return $headers;
			}
		}
		return false;
	}
742301
private function getUrlOrigin($url)
    {
        return array(
            parse_url($url, PHP_URL_SCHEME),
            parse_url($url, PHP_URL_HOST),
            parse_url($url, PHP_URL_PORT),
        );
    }
1253106
public function byURL($url) {
        $URL = \Convert::raw2sql($url);
        return $this->owner->filter('URLSegment', $URL)->first();
    }
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;
    }
486939
public static function getDomain($url)
    {
        $urlInfo = static::info($url);

        return ArrayHelper::get($urlInfo, 'domain', null, true);
    }
1029939
public function getSubdomainOrSubDirectory( $url ) {
		$url = untrailingslashit( $url );
		$host = wp_parse_url( $url, PHP_URL_HOST );
		$path = wp_parse_url( $url, PHP_URL_PATH );
		if ( $path ) {
			return ltrim( $path, '/\\' );
		} else {
			$host = explode( '.', $host );
			$subdomain = array_shift( $host );
			return $subdomain;
		}
	}
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;
    }
629761
public static function getRootDomain($url)
    {
        $host = $domain = self::getHostname($url);
        $root = false;

        if (($dotsCount = substr_count($host, '.')) > 0) {
            $last = $domain;
            while ($dotsCount > -1) {
                if (self::isHostInSuffixList($domain)) {
                    $root = $last;
                    break;
                }
                $last = trim($domain, '.');
                $domain = substr($last, strpos($last, '.'));
                $dotsCount = $dotsCount - 1;
            }
        }

        return $root;
    }
512712
public function convertUrl(string $url): string
    {
        $parsed = parse_url($url);
        if ($parsed === false) {
            throw new InvalidArgumentException('The given string does not look like a URL', 206);
        }

        // Nothing to do
        if ($parsed['host'] === null) {
            return $url;
        }
        $parsed['host'] = $this->convert($parsed['host']);

        return http_build_url($parsed);
    }
600115
protected function getUrlContent($url)
    {
        $contents = '';
        $time = (int) self::MAX_TIMEOUT_MINS * 60;

        $timeout = stream_context_create(array(
            'http' => array(
                'timeout' => $time,
            ),
        ));
        set_time_limit($time);
        ini_set('max_execution_time', $time);

        // check if the URL is valid
        if($this->isValidUrl($url)) {
            // make sure we are not getting 404 when accessing the page
            if( (int) $this->getUrlStatus($url) != self::HTTP_NOT_OK ) {
                // ge the contents of the page
                $contents = @file_get_contents($url, false, $timeout);

                // if the contents has results
                if($contents === true) {
                    // convert encodings
                    $contents = mb_convert_encoding($contents, 'HTML-ENTITIES', self::ENCODING);
                }
            }
        }



        return $contents;
    }
1348129
private function parseUrl($url)
    {
        $parsed = parse_url($url);

        if ((count($parsed) === 1)
            && isset($parsed['path'])
            && (0 === strpos($parsed['path'], '?') || false !== strpos($parsed['path'], '&'))
        ) {
            $parsed = array(
                'query' => $parsed['path']
            );

            return $parsed;
        }

        return $parsed;
    }
475216
public function generateUrl($url)
    {
        $extern = false;
        if ((0 === strrpos($url, 'http://'))
            || (0 === strrpos($url, 'https://'))) {
            $extern = true;
        }

        $http = (isset($_SERVER['HTTPS'])) ? 'https://' : 'http://';

        if (!$extern) {
            return ($this->getRoot() == '/')
                ? (($this->getRoot() == $url) ? '' : $url) : $http.$_SERVER['SERVER_NAME'].$this->getRoot().$url;
        } else {
            return $url;
        }
    }