Created
August 10, 2024 09:38
-
-
Save zhanglianxin/ec1ccd654f38cd54dec6bd4812e23a8b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (!function_exists('is_valid_ip')) { | |
// PHP ≥ 8.0 | |
function is_valid_ip(string $ip, ?string $type = null): bool | |
{ | |
return false !== match ($type) { | |
'IPv4' => filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4), | |
'IPv6' => filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6), | |
default => filter_var($ip, FILTER_VALIDATE_IP), | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment