note 29532 added to function.long2ip
| From: | Tom at rack1 dot php dot net | Date: | Sun, 16 Feb 2003 19:13:35 +0000 |
| Subject: | note 29532 added to function.long2ip | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-44066@lists.php.net to get a copy of this message | ||
I wanted to be able to pass an IP address in a URL always as an unsigned int. I then converted it
back as shown below:
$ip_addr = "192.168.100.25"; // example IP address that converts to neg #
$s32int = ip2long($ip_addr);
$us32str = sprintf("%u",$s32int); // convert to unsigned string
// display orig IP address, signed 32 bit version, unsigned 32 bit ver,
// finally converted back to IP addr
printf("%s ,%d, %s, %s", $ip_addr, $s32int, $us32str,
long2ip(-(4294967296-$us32str)));
// tested on Linux/Apache PHP 4.1.2
--
http://www.php.net/manual/en/function.long2ip.php
http://master.php.net/manage/user-notes.php?action=edit+29532
http://master.php.net/manage/user-notes.php?action=delete+29532
http://master.php.net/manage/user-notes.php?action=reject+29532