note 27212 deleted from function.ip2long by nicos
| From: | nicos@php.net | Date: | Tue, 04 Feb 2003 00:27:21 +0000 |
| Subject: | note 27212 deleted from function.ip2long by nicos | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-43355@lists.php.net to get a copy of this message | ||
I don't think the sprintf or the abs() methods will work because how will you get back the
original IP address? paste this bit of PHP code and see what I mean.
//the range is a signed LONG INT (4 Bytes)
$ip = "192.168.0.5";
echo "IP = ".$ip."<P>";
echo "CORRECT:<BR>";
$long = ip2long($ip);
echo "ip2long() = ".$long."<BR>";
echo "long2ip() = ".long2ip($long)."<P>";
echo "WRONG:<BR>";
$absversion = abs(ip2long($ip));
echo "abs(ip2long()) = ".$absversion."<BR>";
echo "long2ip() = ".long2ip($absversion)."<P>";
echo "WRONG:<BR>";
$sprintversion = sprintf("%u",ip2long($ip));
echo "sprintf %u = ".$sprintversion."<BR>";
echo "long2ip() = ".long2ip($sprintversion)."<BR>";
//FYI: 255.255.255.255 = -1 and 0.0.0.0 = 0