Question

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

How to do that in PHP?

Was it helpful?

Solution

Use good old long2ip() here:

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

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top