[英]Convert hexadecimal string to numeric IP Address in PHP
i want to convert this kind of address 0xC0A8071B to a numeric Ip Address (ex: 192.168.96.55)我想将这种地址0xC0A8071B转换为数字 Ip 地址(例如:192.168.96.55)
How to do that in PHP?如何在 PHP 中做到这一点?
Use good old long2ip()
here:在这里使用旧的long2ip()
:
echo long2ip(0xC0A8071B);
Output:输出:
192.168.7.27
A nice feature is that the parameter can be passed as numeric or string representation, this can be seen here: http://3v4l.org/P8TRB一个不错的功能是参数可以作为数字或字符串表示形式传递,可以在这里看到:http: //3v4l.org/P8TRB
The function ip2long()
can be used to convert into the other direction, from an IP to a number.函数ip2long()
可用于转换为另一个方向,从 IP 到数字。 However, both functions will work with IPv4 addresses only.但是,这两个功能仅适用于 IPv4 地址。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.