mysql - PHP ip2long function not giving current result -
the following code works fine on http://writecodeonline.com/php/
unfortunately cannot provide current output @ localhost.
$eip = '255.255.255.254';
echo $longeip = ip2long($eip);
output should displayed 4294967294 gives 2
for enter code hereip 1.0.0.1 , getting current output 16777217
that's because ip2long() return integer value signed in php, available inteval [-1*2^31 .. 2^31-1]. thus, -2 because of binary representation.
if want unsigned value, use
$longeip = sprintf('%u', ip2long($eip)); here %u specifies "unsigned integer" sprintf(). aware result string in case.
Comments
Post a Comment