I've been reading about how to determine whether an IP is IPv4 or IPv6 and it seems obvious to me that the thing to look for is whether there is a colon. However, then you have IPv4–mapped IPv6 addresses and IPv4–compatible IPv6 addresses. It seems to me that these types of addresses have both colons and periods, so instead of solutions that look for whether there is no ::ffff
at the beginning of the string, why not just do this:
function isIPv6($ip) {
if(strpos($ip, ":") !== false && strpos($ip, ".") === false) {
return true;
}
return false;
}
EDIT: Am I missing something or would this function work properly in all cases?