That's because ip2long()
will return integer value which is signed in PHP, so available inteval is [-1*2^31 .. 2^31-1]
. Thus, it will be -2
because of binary representation.
If you want unsigned value, use
$longeip = sprintf('%u', ip2long($eip));
here %u
specifies "unsigned integer" for sprintf()
. Be aware that result will be string in this case.