PHPMailer\PHPMailer
PHPMailer::isValidHost
Validate whether a string contains a valid value to use as a hostname or IP address. IPv6 addresses must include [], e.g. [::1], not just ::1.
Метод класса: PHPMailer{}
Хуков нет.
Возвращает
true|false.
Использование
$result = PHPMailer::isValidHost( $host );
- $host(строка) (обязательный)
- The host name or IP address to check.
Код PHPMailer::isValidHost() PHPMailer::isValidHost WP 6.9.4
public static function isValidHost($host)
{
//Simple syntax limits
if (
empty($host)
|| !is_string($host)
|| strlen($host) > 256
|| !preg_match('/^([a-z\d.-]*|\[[a-f\d:]+\])$/i', $host)
) {
return false;
}
//Looks like a bracketed IPv6 address
if (strlen($host) > 2 && substr($host, 0, 1) === '[' && substr($host, -1, 1) === ']') {
return filter_var(substr($host, 1, -1), FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !== false;
}
//If removing all the dots results in a numeric string, it must be an IPv4 address.
//Need to check this first because otherwise things like `999.0.0.0` are considered valid host names
if (is_numeric(str_replace('.', '', $host))) {
//Is it a valid IPv4 address?
return filter_var($host, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) !== false;
}
//Is it a syntactically valid hostname (when embedded in a URL)?
return filter_var('https://' . $host, FILTER_VALIDATE_URL) !== false;
}