Extracts the domain from a URL

@param $url string The URL

@return string The domain (with port)
347777
public static function getDomainFromURL($url)
	{
		$url = str_replace(self::getProtocolFromURL($url) . '://', '', $url);
		
		return explode('/', $url)[0];
	}
1031516
public static function parse_url( $url ) {
		$r             = wp_parse_url( $url );
		$r['pathname'] = empty( $r['path'] ) ? '/' : $r['path'];
		return $r;
	}
1307705
protected function parseUrl(string $url)
    {
        $url = trim($url, '/');

        // Proceed if the URL is still a valid URL
        if (filter_var($url, FILTER_VALIDATE_URL)) {
            // Return an URL with a '/' if is just a domain
            return preg_match('/(\.(?<tld>\w*))$/m', $url)
                ? $url . '/'
                : $url;
        }

        throw new InvalidUrlException($url);
    }
142174
private function parseUrl($url)
	{
		$newUrl = preg_replace($this->patterns, $this->replacements, $url);
		$newUrl = trim($newUrl, '\/?');
		$newUrl = trim($newUrl, '\/');

		return $newUrl;
	}
88414
public static function wwwLess($url) {
		if (strpos($url, 'www.') === 0 && substr_count($url, '.') > 1) {
			$url = substr($url, 4);
		}
		return $url;
	}
493559
protected function extractCCLicense( $url ) {
		$license = '';

		// evaluate that it's a url
		if ( ! is_string( $url ) ) {
			return $license;
		}
		// look for creativecommons domain
		$parts = wp_parse_url( $url );

		if ( 'http' === $parts['scheme'] && 'creativecommons.org' === $parts['host'] ) {
			// extract the license information from it
			$split = explode( '/', $parts['path'] );
			if ( 'zero' === $split[2] ) {
				$license = 'cc0';
			} else {
				$license = 'cc-' . $split[2];
			}
		}

		return $license;
	}
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'];
    }
424047
public static function getSubDomain($url)
    {
        $urlInfo = static::info($url);

        return ArrayHelper::get($urlInfo, 'sub', null, true);
    }
613031
static public function getSecondDomain($domain=null)
	{
	    $domain = !empty($domain) ? $domain : (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : null);
	    $n = preg_match('/([^.]*\.)?([^.]*\.)?\w+\.\w+$/', $domain, $matches);
	    return $domain && isset($matches[2]) ? $matches[2] : (isset($matches[1]) ? $matches[1] : '');
	}
540478
protected function getUrlContents(string $url): string
    {
        $request = $this->getRequest($url);

        return $this->getParsedResponse($request);
    }
371100
private static function encodeUrl($url)
    {
        $url_parsed = parse_url($url);
        $scheme = $url_parsed['scheme'] . '://';
        $host   = $url_parsed['host'];
        $port   = (isset($url_parsed['port']) ? $url_parsed['port'] : null);
        $path   = (isset($url_parsed['path']) ? $url_parsed['path'] : null);
        $query  = (isset($url_parsed['query']) ? $url_parsed['query'] : null);
        if ($query != null) {
            $query = '?' . http_build_query(self::getArrayFromQuerystring($url_parsed['query']));
        }
        if ($port && $port[0] != ":") {
            $port = ":" . $port;
        }
        $result = $scheme . $host . $port . $path . $query;
        return $result;
    }
880401
function extractDomain (url) {
  // Find and remove protocol (e.g., http, ftp, etc.) to get domain.
  var domain = url.indexOf('://') > -1 ? url.split('/')[2] : url.split('/')[0];

  // Find and remove port number.
  return domain.substring(0, domain.indexOf(':'));
}
962611
public static function getPortFromURL($url)
	{
		$url = self::getDomainFromURL($url);
		$url = explode(':', $url);
		
		if(count($url) == 1)
		{
			return 80;
		}
		else
		{
			if(!is_numeric($url[1]))
				return 80;
			else
				return (integer) $url[1];
		}
	}
1253106
public function byURL($url) {
        $URL = \Convert::raw2sql($url);
        return $this->owner->filter('URLSegment', $URL)->first();
    }
919349
protected static function parseUrl($url)
	{
		$regexp = '(^(?:([a-z][-+.\\w]*):)?(?://(?:([^:/?#]*)(?::([^/?#]*)?)?@)?(?:(\\[[a-f\\d:]+\\]|[^:/?#]+)(?::(\\d*))?)?(?![^/?#]))?([^?#]*)(\\?[^#]*)?(#.*)?$)Di';

		// NOTE: this regexp always matches because of the last three captures
		preg_match($regexp, $url, $m);

		$parts  = [];
		$tokens = ['scheme', 'user', 'pass', 'host', 'port', 'path', 'query', 'fragment'];
		foreach ($tokens as $i => $name)
		{
			$parts[$name] = (isset($m[$i + 1])) ? $m[$i + 1] : '';
		}

		/**
		* @link http://tools.ietf.org/html/rfc3986#section-3.1
		*
		* 'An implementation should accept uppercase letters as equivalent to lowercase in
		* scheme names (e.g., allow "HTTP" as well as "http") for the sake of robustness but
		* should only produce lowercase scheme names for consistency.'
		*/
		$parts['scheme'] = strtolower($parts['scheme']);

		/**
		* Normalize the domain label separators and remove trailing dots
		* @link http://url.spec.whatwg.org/#domain-label-separators
		*/
		$parts['host'] = rtrim(preg_replace("/\xE3\x80\x82|\xEF(?:\xBC\x8E|\xBD\xA1)/s", '.', $parts['host']), '.');

		// Test whether host has non-ASCII characters and punycode it if possible
		if (preg_match('#[^[:ascii:]]#', $parts['host']) && function_exists('idn_to_ascii'))
		{
			$variant = (defined('INTL_IDNA_VARIANT_UTS46')) ? INTL_IDNA_VARIANT_UTS46 : 0;
			$parts['host'] = idn_to_ascii($parts['host'], 0, $variant);
		}

		return $parts;
	}
409080
public static function resolve_url($url)
    {
        // prepend protocol://hostname:port
        if (!preg_match('|^https?://|', $url)) {
            $schema       = 'http';
            $default_port = 80;

            if (self::https_check()) {
                $schema       = 'https';
                $default_port = 443;
            }

            $prefix = $schema . '://' . preg_replace('/:\d+$/', '', $_SERVER['HTTP_HOST']);
            if ($_SERVER['SERVER_PORT'] != $default_port) {
                $prefix .= ':' . $_SERVER['SERVER_PORT'];
            }

            $url = $prefix . ($url[0] == '/' ? '' : '/') . $url;
        }

        return $url;
    }
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;
        }
    }