Convert IPv6 to IPV4 PHP

非 Y 不嫁゛ 提交于 2020-01-18 00:01:08

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!