: , ? inet_pton() , , , .
, ::192.168.0.1 0000:0000:0000:0000:0000:0000:c0a8:0001, . , .
0000:0000:0000:0000:0000:0000:192.168.0.1 inet_pton(), inet_ntop(), IPv6, ::192.168.0.1. ::, : , , IPv4-; -)
:
function expand_ip_address($addr_str) {
$addr_bin = @inet_pton($addr_str);
if ($addr_bin === FALSE) {
return FALSE;
}
$addr_hex = bin2hex($addr_bin);
if (strlen($addr_bin) == 16
&& substr($addr_hex, 0, 20) == str_repeat('0', 20)) {
if (substr($addr_hex, 20, 4) == '0000')
|| substr($addr_hex, 20, 4) == 'ffff')) {
$addr_bin = substr($addr_hex, 12);
}
}
if (strlen($addr_bin) == 4) {
$ipv4_bytes = str_split($addr_bin);
$ipv4_ints = array_map('ord', $ipv4_bytes);
return vsprintf('%03d.%03d.%03d.%03d', $ipv4_ints);
} else {
return implode(':', str_split($addr_hex, 4));
}
}