get the type of a url by its host
@param string $url
@return string
182470
public static function urlType($url) {
        $parsed = parse_url($url);
        if (isset($parsed['host'])) {
            $hostname = $parsed['host'];
        } else {
            $hostname = $url;
        }
        if (strpos($hostname, 'youtube') > 0) {
            return 'youtube';
        } elseif (strpos($hostname, 'vimeo') > 0) {
            return 'vimeo';
        } else {
            return 'unknown';
        }
    }
1015758
protected function getHTML( $url )
	{
		$this->reader->setUrl( $url );
		try
		{
			$content	= $this->reader->read( array(
				'CURLOPT_FOLLOWLOCATION'	=> TRUE,
				'CURLOPT_COOKIEJAR'			=> 'cookies.txt', 
				'CURLOPT_COOKIEFILE'		=> 'cookies.txt'
			) );
			$contentType	= $this->reader->getInfo( 'content_type' );
			return $contentType === 'text/html' ? $content : '';
		}
		catch( RuntimeException $e )
		{
			$this->errors[$url]	= $e->getMessage();
			throw $e;
		}
	}
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;
    }
1052478
public function getAbsolute($url)
    {
        $url = trim($url);

        if (empty($url)) {
            return '';
        }

        if (preg_match('|^\w+:[^/]|', $url)) {
            return $url;
        }

        if (preg_match('|^\w+://|', $url)) {
            return self::validUrlOrEmpty($url);
        }

        if (strpos($url, '://') === 0) {
            return self::validUrlOrEmpty($this->getScheme().$url);
        }

        if (strpos($url, '//') === 0) {
            return self::validUrlOrEmpty($this->getScheme().":$url");
        }

        if ($url[0] === '/') {
            return self::validUrlOrEmpty($this->getScheme().'://'.$this->getHost().$url);
        }

        return self::validUrlOrEmpty($this->getScheme().'://'.$this->getHost().$this->getDirectories().$url);
    }
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;
    }
1090429
protected function getHost($url)
    {
        $data = parse_url($url);
        if (empty($data['host'])) {
            throw new \InvalidArgumentException('The Url: ' . $url . ' seems to be invalid');
        }

        $host = preg_replace('~^(?:www|player)\.~i', '', strtolower($data['host']));
        if (isset($this->services[$host])) {
            return $host;
        } else if (isset($this->services['*.' . $host])) {
            return '*.' . $host;
        } else if (!empty($this->wildCardHosts)) {
            $trans = array('\*' => '(?:.*)');
            foreach ($this->wildCardHosts as $value) {
                $regex = strtr(preg_quote($value, '~'), $trans);
                if (preg_match('~' . $regex . '~i', $host)) {
                    return $value;
                }
            }
        }

        return $host;
    }
1180065
public static function extractHost($url)
    {
        $parsedUrl = parse_url($url);

        if (count($parsedUrl) == 1 && isset($parsedUrl['path'])) {
            $host = $parsedUrl['path'];
        } else {
            $host = $parsedUrl['host'];
        }

        if (substr($host, 0, 4) == 'www.') {
            $host = substr($host, 4);
        }

        return $host;
    }
1189820
public function url($url)
    {
        if (is_string($url)) {
            $url = $this->localePrefix($url);
        }

        try {
            $url = Router::url($url, true);
        } catch (\Exception $ex) {
            $url = '';
        }

        return $url;
    }
251783
public static function getResourceTypeFromUrl($url)
    {
        $matchFound = preg_match('/\/v[23]\/(\w+)[\/?]?/', $url, $matches);
        if( ! $matchFound || ! is_array($matches) || ! isset($matches[1])) {
            throw new \Exception('Unable to find resource type in url', 1462733277);
        }

        if ($matches[1] == 'getReport') {
            return 'report';
        } elseif ($matches[1] == 'price') {
            return 'prices';
        }

        return $matches[1];
    }
298147
public function path($url) {
        $prefix = $this->config['url_prefix'];

        // If the url_prefix is absolute-path style but the url isn't, get only the
        // path from the URL before comparing against the prefix.
        if (preg_match('#^/#', $prefix) && preg_match('#^http#', $url)) {
            $url = parse_url($url, PHP_URL_PATH);
        }

        // Trim the prefix from the URL
        return substr($url, strlen($prefix));
    }
781887
public static function getHostname(string $url)
    {
        $url = UrlHelper::validateUrl($url);

        $hostname = parse_url($url, PHP_URL_HOST);
        if ($hostname === false) {
            throw new InvalidArgumentException("Could not determine hostname, url seems to be invalid: $url");
        }

        return $hostname;
    }
528963
public function getUrl($url)
    {
        if (!$url || starts_with($url, ['#', '//', 'mailto:', 'tel:', 'http'])) {
            return $url;
        }

        // Get URL root
        $root = $this->app->getSetting('url');

        $url = trim($root, '/') . '/' . trim($url, '/');

        // Force trailing slash
        if ($this->app->getSetting('url_trailing_slash', false)
            && ! strrchr(basename($url), '.')
        ) {
            $url = "{$url}/";
        }

        return $url;
    }
548823
public static function url($url){

		$url = static::_nullValue($url);
		if(!$url){

			return $url;
		}

		$query = parse_url($url, PHP_URL_QUERY);
		if(!$query){

			return $url;
		}

		parse_str($query, $query_parts);

		// First urldecode to be sure that we do not re-encode the query parts.
		$query_parts = array_map('static::_nested_urldecode', $query_parts);

		// http_build_query will take care of the urlencode.
		return strtok($url, '?') . '?' . http_build_query($query_parts);
	}
203868
private function extractHostname($url)
    {
        $url = trim(Str::lower($url));

        // Removes scheme and path i.e. "https://github.com/layershifter" to "github.com/layershifter".

        $url = preg_replace(static::SCHEMA_PATTERN, '', $url);

        // Removes path and query part of URL i.e. "github.com/layershifter" to "github.com".

        $url = $this->fixUriParts($url);
        $hostname = Arr::first(explode('/', $url, 2));

        // Removes username from URL i.e. user@github.com to github.com.

        $hostname = Arr::last(explode('@', $hostname));

        // Remove ports from hosts, also check for IPv6 literals like "[3ffe:2a00:100:7031::1]".
        //
        // @see http://www.ietf.org/rfc/rfc2732.txt

        $lastBracketPosition = Str::strrpos($hostname, ']');

        if ($lastBracketPosition !== false && Str::startsWith($hostname, '[')) {
            return Str::substr($hostname, 1, $lastBracketPosition - 1);
        }

        // This is either a normal hostname or an IPv4 address, just remove the port.

        $hostname = Arr::first(explode(':', $hostname));

        // If string is empty, null will be returned.

        return '' === $hostname ? null : $hostname;
    }
1370223
protected function urlValidate($url)
    {
        return (
            filter_var($url, FILTER_VALIDATE_URL) &&
            ($parsed = parse_url($url)) !== false &&
            $this->urlValidateHost($parsed['host']) &&
            $this->urlValidateScheme($parsed['scheme'])
        );
    }
1091628
public function prepUrl($url)
	{
        if (empty($url)) {
            return '';
        }

        return parse_url($url, PHP_URL_SCHEME) === null ? 'http://' . $url : $url;
	}
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;
    }