Parse a host_port string to construct the HostPost object.

@param string the host_port string
@return the HostPort object
960716
public static HostPort parseHostPort(String string) {
    String[] strings = string.split("_");
    return new HostPort(strings[0], Integer.parseInt(strings[1]));
  }
729371
public function parseHost($string) {
        $segments = [
            'tld' => null,
            'domain' => null,
            'subdomain' => null,
        ];

        $parts = explode('.', $string);

        if (count($parts) == 1) {
            $segments['domain'] = $parts[0];

            return $segments;
        }

        if (count($parts)) {
            $segments['tld'] = array_pop($parts);
        }

        if (count($parts)) {
            $segments['domain'] = array_pop($parts);
        }

        if (count($parts)) {
            $segments['subdomain'] = implode('.', $parts);
        }

        return $this->replaceEmptyStringsWithNull($segments);
    }
499451
public function parse( $string ) {
        $data = parse_url( $string );
        
        //helper function gets $a[$k], checks if exists
        function get( $a, $k ) {
            if( array_key_exists( $k, $a ) ) {
                return empty( $a[$k] ) ? null : $a[$k];
            }
            
            return null;
        }
        
        if( $data === null ) {
            return null;
        }
        
        $uri = new Uri;
        
        $uri->setProtocol( get( $data, 'scheme' ) );
        $uri->setUsername( get( $data, 'user' ) );
        $uri->setPassword( get( $data, 'pass' ) );
        $uri->setHost( get( $data, 'host' ) );
        $uri->setPort( get( $data, 'port' ) );
        $uri->setPath( get( $data, 'path' ) );
        $uri->setQuery( get( $data, 'query' ) );
        $uri->setAnchor( get( $data, 'anchor' ) );
        
        return $uri;
    }
1183591
public function parse($string) {
        $segments = $this->parseSegments($string);
        $segments = array_extend($segments, $this->parseHost(array_get($segments, 'host')));

        return $this->replaceEmptyStringsWithNull($segments);
    }
422552
public static function tryParse(string $hostname): ?HostnameInterface
    {
        if (!self::myParse($hostname, $domainParts, $tld)) {
            return null;
        }

        return new self($domainParts, $tld);
    }
433769
public static function parse_host($name, $host = '')
    {
        if (!is_string($name)) {
            return $name;
        }

        // %n - host
        $n = preg_replace('/:\d+$/', '', $_SERVER['SERVER_NAME']);
        // %t - host name without first part, e.g. %n=mail.domain.tld, %t=domain.tld
        $t = preg_replace('/^[^\.]+\./', '', $n);
        // %d - domain name without first part
        $d = preg_replace('/^[^\.]+\./', '', $_SERVER['HTTP_HOST']);
        // %h - IMAP host
        $h = $_SESSION['storage_host'] ?: $host;
        // %z - IMAP domain without first part, e.g. %h=imap.domain.tld, %z=domain.tld
        $z = preg_replace('/^[^\.]+\./', '', $h);
        // %s - domain name after the '@' from e-mail address provided at login screen.
        //      Returns FALSE if an invalid email is provided
        if (strpos($name, '%s') !== false) {
            $user_email = self::get_input_value('_user', self::INPUT_POST);
            $user_email = self::idn_convert($user_email, true);
            $matches    = preg_match('/(.*)@([a-z0-9\.\-\[\]\:]+)/i', $user_email, $s);
            if ($matches < 1 || filter_var($s[1]."@".$s[2], FILTER_VALIDATE_EMAIL) === false) {
                return false;
            }
        }

        return str_replace(array('%n', '%t', '%d', '%h', '%z', '%s'), array($n, $t, $d, $h, $z, $s[2]), $name);
    }
1313108
func ParseHostPort(hostport string) (string, string, error) {
	var host, port string
	var err error

	// try to split host and port
	if host, port, err = net.SplitHostPort(hostport); err != nil {
		// if SplitHostPort returns an error, the entire hostport is considered as host
		host = hostport
	}

	// if port is defined, parse and validate it
	if port != "" {
		if _, err := ParsePort(port); err != nil {
			return "", "", errors.Errorf("hostport %s: port %s must be a valid number between 1 and 65535, inclusive", hostport, port)
		}
	}

	// if host is a valid IP, returns it
	if ip := net.ParseIP(host); ip != nil {
		return host, port, nil
	}

	// if host is a validate RFC-1123 subdomain, returns it
	if errs := validation.IsDNS1123Subdomain(host); len(errs) == 0 {
		return host, port, nil
	}

	return "", "", errors.Errorf("hostport %s: host '%s' must be a valid IP address or a valid RFC-1123 DNS subdomain", hostport, host)
}
900102
@Override
  protected CharSequence getHost()
  {
    if (_host != null)
      return _host;

    if (_uriHost.length() > 0) {
      _host = _uriHost;
    }
    else if ((_host = getForwardedHostHeader()) != null) {
    }
    else {
      _host = getHostHeader();
    }

    return _host;
  }
1353072
def get_host(url):
    
    p = parse_url(url)
    return p.scheme or 'http', p.hostname, p.port
376015
public static function parseDsn($string = null)
	{
		$opts = null;

		if (!empty($string)) {
			$dsn = new DSN($string);

			$port = empty($dsn->getFirstPort()) ? '' : (':' . $dsn->getFirstPort());
			$password = empty($dsn->getPassword()) ? null : $dsn->getPassword();

			$opts = [
				'driver'	=> $dsn->getProtocol(),
				'host'		=> $dsn->getFirstHost() . $port,
				'database'	=> $dsn->getDatabase(),
				'username'	=> $dsn->getUsername(),
				'password'	=> $password
			];
		}

		return $opts;
	}
1168880
public static HostAndPort of(String host, int port) {

        LettuceAssert.isTrue(isValidPort(port), String.format("Port out of range: %s", port));

        HostAndPort parsedHost = parse(host);
        LettuceAssert.isTrue(!parsedHost.hasPort(), String.format("Host has a port: %s", host));
        return new HostAndPort(host, port);
    }
1067104
function tryParse(url) {
  if (!url) {
    return null;
  }

  var conf = {};
  var parsed = urlParse(url);
  conf.protocol = parsed.protocol;
  conf.host = parsed.hostname;
  conf.port = parseInt(parsed.port,10);
  return conf;
}
1045375
public function referer( $valid_host = false, $valid_string = '' )
	{
		$ref = $this->server->getOr('HTTP_REFERER', '');
		if( $ref ) {

			if($valid_host) {
				$host = BASE_PROTOCOL . "://" . APP_HOST;
				$len = strlen($host);

				if( substr($ref, 0, $len) !== $host ) {
					return '';
				}

				if( strlen($ref) > $len ) {
					$end = $ref[$len];
					if( $end !== "/" && $end !== ":" ) {
						return '';
					}
				}
			}

			if($valid_string && strpos($ref, $valid_string) === false) {
				return '';
			}
		}

		return $ref;
	}
275214
public String getHostAndPort()
  {
    if (enablePlaintextPort) {
      if (plaintextPort < 0) {
        return HostAndPort.fromString(host).toString();
      } else {
        return HostAndPort.fromParts(host, plaintextPort).toString();
      }
    }
    return null;
  }
9450
String toUriString(String defaultScheme, String defaultHostname, int defaultPort) {
        requireNonNull(defaultScheme, "defaultScheme");
        requireNonNull(defaultHostname, "defaultHostname");
        validatePort(defaultPort);

        final StringBuilder sb = new StringBuilder();
        sb.append(firstNonNull(uri.getScheme(), defaultScheme)).append("://")
          .append(firstNonNull(uri.getHost(), defaultHostname)).append(':')
          .append(uri.getPort() > 0 ? uri.getPort() : defaultPort)
          .append(uri.getPath());
        return sb.toString();
    }
74967
protected ParseLoginAddress parseServerAddressValue() throws IllegalArgumentException {

		ParseLoginAddress serverAddress = new ParseLoginAddress(this.inputAddress, this.commandConsole);
		// parse <user>:<password>@<host>:<port>
		serverAddress.parseLoginAddressValue("--server");
		
		return serverAddress;
	}
1254744
protected function buildHostString()
    {
        $scheme = $this->getScheme();
        $host = $this->getHost();
        $port = $this->getPort();

        $hostString = $this->prepareHost($scheme, $host);

        if (!is_null($port)) {
            $hostString = $hostString . ":" . $port;
        }

        return $hostString;
    }