问题
I have a list of IPv4 IPs selected from a database which stores the addresses as BINARY(16). Is there any simple way to convert the IPv6 formated address to human readable IPv4 format?
This is what the IPv4 address looks like 8ab8:7f70::
回答1:
As Ron Maupin described, the solution is very simple
$ipv6 = "8ab8:7f70::";
$ipv4 = hexdec(substr($ipv6, 0, 2)). "." . hexdec(substr($ipv6, 2, 2)). "." . hexdec(substr($ipv6, 5, 2)). "." . hexdec(substr($ipv6, 7, 2));
来源:https://stackoverflow.com/questions/38663960/convert-ipv6-to-ipv4-php