Replaces hostname variables.

@param string $name Hostname
@param string $host Optional IMAP hostname

@return string Hostname
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);
    }
1265342
private static String formatIPv6Addr(String host) {
        if (host == null) {
            return null;
        } else {
            return (new StringBuilder()).append("[").append(host).append("]").toString();
        }
    }
1112625
public static function hostParts($host = null) {
		if (empty($host)) {
			$host = self::host();
		}
		$host = str_replace(['http://', 'https://', '/'], '', $host);
		$temp = explode('.', $host);
		krsort($temp);
		$result = [];
		$counter = 1;
		foreach ($temp as $k => $v) {
			$result[$counter] = $v;
			$counter++;
		}
		return $result;
	}
1271468
protected function normalizeHost($host) {
		if ($host instanceof Url) {
			return $host;
		}
		
		if (is_numeric($host)) {
			return new Url(['port' => $host]);
		}
		
		if (is_string($host) && ! preg_match('~^[a-z]://~', $host)) {
			return new Url('mongodb://' . $host);
		}
		
		return new Url($host);
	}
185460
protected function getmxrr($hostname, &$mxhosts, &$mxweights)
        {
            if (!Arrays::is($mxhosts)) {
                $mxhosts = array();
            }
            if (!Arrays::is($mxweights)) {
                $mxweights = array();
            }
            if (empty($hostname)) {
                return;
            }
            $cmd = 'nslookup -type=MX ' . escapeshellarg($hostname);
            if (!empty($this->mx_query_ns)) {
                $cmd .= ' ' . escapeshellarg($this->mx_query_ns);
            }
            exec($cmd, $output);
            if (empty($output)) {
                return;
            }
            $i = -1;
            foreach ($output as $line) {
                $i++;
                if (preg_match("/^$hostname\tMX preference = ([0-9]+), mail exchanger = (.+)$/i", $line, $parts)) {
                    $mxweights[$i] = trim($parts[1]);
                    $mxhosts[$i] = trim($parts[2]);
                }
                if (preg_match('/responsible mail addr = (.+)$/i', $line, $parts)) {
                    $mxweights[$i] = $i;
                    $mxhosts[$i] = trim($parts[1]);
                }
            }
            return ($i != -1);
        }
489090
public static String normalizeHostName(String name) {
    try {
      return InetAddress.getByName(name).getHostAddress();
    } catch (UnknownHostException e) {
      return name;
    }
  }
794445
protected static function encodeHost(string $host): string
    {
        // http://tools.ietf.org/html/rfc3986#section-3.2.2
        // IP-literal = "[" ( IPv6address / IPvFuture  ) "]"
        // IPvFuture  = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" )
        if ($host[0] === '[') {
            $excluded = static::UNRESERVED_SET.static::SUB_DELIMS_SET.'\[\]:';

            return static::encode($host, $excluded);
        }

        // http://tools.ietf.org/html/rfc3986#section-3.2.2
        // NOTE: characters in IPv4 address are all in the unreserved set
        // IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octet
        // reg-name    = *( unreserved / pct-encoded / sub-delims )
        $excluded = static::UNRESERVED_SET.static::SUB_DELIMS_SET;

        return static::encode($host, $excluded);
    }
1053279
public function withHost(string $host): URI
    {
        $result = clone $this;
        $result->host = $this->filterHost($host);

        return $result;
    }
497289
protected function setPreserveHost(string $headerHost, string $host)
        {
            $header = [];
            if ($host !== '' && $headerHost === '') {
                $header = [
                    'original' => 'HTTP_HOST', 
                    'values'   => [$host]
                ];
            }
            return $header;
        }
422552
public static function tryParse(string $hostname): ?HostnameInterface
    {
        if (!self::myParse($hostname, $domainParts, $tld)) {
            return null;
        }

        return new self($domainParts, $tld);
    }
1258728
public function getRegisteredDomain($host)
    {
        $this->tree = $this->psl->getTree();

        $signingDomain = $this->normalizeHost($host);
        $signingDomainParts = explode('.', $signingDomain);

        $result = $this->findRegisteredDomain($signingDomainParts, $this->tree);

        if (empty($result)) {
            // this is an invalid domain name
            return null;
        }

        // assure there is at least 1 TLD in the stripped signing domain
        if (!strpos($result, '.')) {
            $cnt = count($signingDomainParts);
            if ($cnt == 1 || $signingDomainParts[$cnt-2] == '') {
                return null;
            }
            return $signingDomainParts[$cnt-2] . '.' . $signingDomainParts[$cnt-1];
        }
        return $result;
    }
1270811
public static String normalizeHostName(String name) {
		if (Character.digit(name.charAt(0), 16) != -1) { // it is an IP
			return name;
		} else {
			try {
				InetAddress ipAddress = InetAddress.getByName(name);
				return ipAddress.getHostAddress();
			} catch (UnknownHostException e) {
				return name;
			}
		}
	}
491987
public function removeHost($host)
    {
        $ips = $this->getIp($host);
        unset($this->hosts[$host]);
        foreach ($ips as $ip) {
            unset($this->ips[$ip][$host]);
        }
    }
214661
public function setHost(string $hostname)
    {
        if (($ppos = strrpos($hostname, ":")) !== false)
        {
            $this->port = substr($hostname, $ppos + 1);
            $hostname = substr($hostname, 0, $ppos);
        }

        if (substr($hostname, 0, 4) === "xn--")
            $hostname = \idn_to_utf8($hostname);

        $this->host = strtolower($hostname);
        return $this;
    }
1039417
public static function serializeHost($host)
    {
        if (is_int($host) || is_float($host)) {
            $string = self::serializeIPv4($host);
        } elseif (is_array($host)) {
            $string = '[' . self::serializeIPv6($host) . ']';
        } else {
            $string = (string)$host;
        }
        return $string;
    }
570294
public function setHost($host)
    {
        if (preg_match(self::PATTERN_MATCH_HOST, $host) !== 1) {
            throw new \InvalidArgumentException('"' . $host . '" is not valid host as part of a URI.', 1184071240);
        }

        $this->host = $host;
    }
101088
public function deleteCommand($hostname)
    {
        $domains = $this->findDomainsByHostnamePattern($hostname);
        if (empty($domains)) {
            $this->outputLine('<error>No domain found for hostname-pattern "%s".</error>', [$hostname]);
            $this->quit(1);
        }
        foreach ($domains as $domain) {
            $site = $domain->getSite();
            if ($site->getPrimaryDomain() === $domain) {
                $site->setPrimaryDomain(null);
                $this->siteRepository->update($site);
            }
            $this->domainRepository->remove($domain);
            $this->outputLine('Domain entry "%s" deleted.', [$domain->getHostname()]);
        }
    }