在PHP中将十六进制字符串转换为数字IP地址 [英] Convert hexadecimal string to numeric IP Address in PHP

查看:225
本文介绍了在PHP中将十六进制字符串转换为数字IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将这种地址 0xC0A8071B 转换为数字IP地址(例如:192.168.96.55)

i want to convert this kind of address 0xC0A8071B to a numeric Ip Address (ex: 192.168.96.55)

如何在PHP中做到这一点?

How to do that in PHP?

推荐答案

使用良好的旧版 long2ip() 此处:

Use good old long2ip() here:

echo long2ip(0xC0A8071B);

输出:

192.168.7.27

一个不错的功能是参数可以以数字或字符串表示形式传递,可以在这里看到: http://3v4l.org/P8TRB

A nice feature is that the parameter can be passed as numeric or string representation, this can be seen here: http://3v4l.org/P8TRB

功能ip2long()可用于转换为从IP到数字的另一个方向.但是,这两个功能仅适用于IPv4地址.

The function ip2long() can be used to convert into the other direction, from an IP to a number. However, both functions will work with IPv4 addresses only.

这篇关于在PHP中将十六进制字符串转换为数字IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆