views:

255

answers:

1

Are there any PHP equivalents for these two functions? I tried searching but couldn't see anything.

Thanks.

+4  A: 

You want ip2long() and long2ip().

$ip = '192.0.34.166';
printf("%u\n", ip2long($ip)); // 3221234342

As it notes in the manual:

Note: Because PHP's integer type is signed, and many IP addresses will result in negative integers, you need to use the "%u" formatter of sprintf() or printf() to get the string representation of the unsigned IP address.

Greg