public static function parse_host_parts($host) {
		// Tease out the hostname.
		if (false === ($host = static::parse_host($host))) {
			return false;
		}

		$out = static::HOST_PARTS;

		// If this is an IP, we don't have to do anything else.
		if (\filter_var($host, \FILTER_VALIDATE_IP)) {
			$out['host'] = $host;
			$out['domain'] = $host;
			return $out;
		}

		// Now the hard part. See if any parts of the host
		// correspond to a registered suffix.
		$suffixes = data::SUFFIXES;
		$suffix = array();
		$parts = \explode('.', $host);
		$parts = \array_reverse($parts);

		foreach ($parts as $k=>$part) {
			// Override rule.
			if (isset($suffixes[$part], $suffixes[$part]['!'])) {
				break;
			}

			// A match.
			if (isset($suffixes[$part])) {
				\array_unshift($suffix, $part);
				$suffixes = $suffixes[$part];
				unset($parts[$k]);
				continue;
			}

			// A wildcard.
			if (isset($suffixes['*'])) {
				\array_unshift($suffix, $part);
				$suffixes = $suffixes['*'];
				unset($parts[$k]);
				continue;
			}

			// We're done.
			break;
		}

		// The suffix can't be all there is.
		if (! \count($parts)) {
			return false;
		}

		// The domain.
		$parts = \array_reverse($parts);
		$out['domain'] = \array_pop($parts);

		// The subdomain.
		if (\count($parts)) {
			$out['subdomain'] = \implode('.', $parts);
		}

		// The suffix.
		if (\count($suffix)) {
			$out['suffix'] = \implode('.', $suffix);
		}

		$out['host'] = $host;

		return $out;
	}
public static function parse_host_parts($host) {
		// Tease out the hostname.
		if (false === ($host = static::parse_host($host))) {
			return false;
		}

		$out = static::HOST_PARTS;

		// If this is an IP, we don't have to do anything else.
		if (\filter_var($host, \FILTER_VALIDATE_IP)) {
			$out['host'] = $host;
			$out['domain'] = $host;
			return $out;
		}

		// Now the hard part. See if any parts of the host
		// correspond to a registered suffix.
		$suffixes = data::SUFFIXES;
		$suffix = array();
		$parts = \explode('.', $host);
		$parts = \array_reverse($parts);

		foreach ($parts as $k=>$part) {
			// Override rule.
			if (isset($suffixes[$part], $suffixes[$part]['!'])) {
				break;
			}

			// A match.
			if (isset($suffixes[$part])) {
				\array_unshift($suffix, $part);
				$suffixes = $suffixes[$part];
				unset($parts[$k]);
				continue;
			}

			// A wildcard.
			if (isset($suffixes['*'])) {
				\array_unshift($suffix, $part);
				$suffixes = $suffixes['*'];
				unset($parts[$k]);
				continue;
			}

			// We're done.
			break;
		}

		// The suffix can't be all there is.
		if (! \count($parts)) {
			return false;
		}

		// The domain.
		$parts = \array_reverse($parts);
		$out['domain'] = \array_pop($parts);

		// The subdomain.
		if (\count($parts)) {
			$out['subdomain'] = \implode('.', $parts);
		}

		// The suffix.
		if (\count($suffix)) {
			$out['suffix'] = \implode('.', $suffix);
		}

		$out['host'] = $host;

		return $out;
	}
public static function parse_host_parts ( $ host ) { // Tease out the hostname. if ( false === ( $ host = static :: parse_host ( $ host ) ) ) { return false ; } $ out = static :: HOST_PARTS ; // If this is an IP, we don't have to do anything else. if ( \ filter_var ( $ host , \ FILTER_VALIDATE_IP ) ) { $ out [ 'host' ] = $ host ; $ out [ 'domain' ] = $ host ; return $ out ; } // Now the hard part. See if any parts of the host // correspond to a registered suffix. $ suffixes = data :: SUFFIXES ; $ suffix = array ( ) ; $ parts = \ explode ( '.' , $ host ) ; $ parts = \ array_reverse ( $ parts ) ; foreach ( $ parts as $ k => $ part ) { // Override rule. if ( isset ( $ suffixes [ $ part ] , $ suffixes [ $ part ] [ '!' ] ) ) { break ; } // A match. if ( isset ( $ suffixes [ $ part ] ) ) { \ array_unshift ( $ suffix , $ part ) ; $ suffixes = $ suffixes [ $ part ] ; unset ( $ parts [ $ k ] ) ; continue ; } // A wildcard. if ( isset ( $ suffixes [ '*' ] ) ) { \ array_unshift ( $ suffix , $ part ) ; $ suffixes = $ suffixes [ '*' ] ; unset ( $ parts [ $ k ] ) ; continue ; } // We're done. break ; } // The suffix can't be all there is. if ( ! \ count ( $ parts ) ) { return false ; } // The domain. $ parts = \ array_reverse ( $ parts ) ; $ out [ 'domain' ] = \ array_pop ( $ parts ) ; // The subdomain. if ( \ count ( $ parts ) ) { $ out [ 'subdomain' ] = \ implode ( '.' , $ parts ) ; } // The suffix. if ( \ count ( $ suffix ) ) { $ out [ 'suffix' ] = \ implode ( '.' , $ suffix ) ; } $ out [ 'host' ] = $ host ; return $ out ; }
Parse Host Parts

Break a host down into subdomain, domain, and
suffix parts.

@param string $host Host.
@return array|bool Parts or false.
Parse Host Parts