ID: 43690
Updated by: [EMAIL PROTECTED]
Reported By: yardgnomeray at gmail dot com
Status: Open
Bug Type: Strings related
Operating System: Windows XP SP2
PHP Version: 5.2.5
New Comment:
I'm using PHP 5.3.0-dev (cli) (built: Dec 25 2007 10:07:55), and the
convertion was necessary.
Previous Comments:
------------------------------------------------------------------------
[2007-12-29 10:22:44] [EMAIL PROTECTED]
@felipe... you're wrong here - this works just fine without having to
cast to float:
[EMAIL PROTECTED]:~$ php-5.2.5RC2
<?php
$ip = "213.10.212.144";
$ipaddr = sprintf("%u",ip2long($ip));
$address = sprintf("IP ADDR = %u", $ipaddr);
echo $address;
?>
IP ADDR = 3574256784d
------------------------------------------------------------------------
[2007-12-28 14:46:42] [EMAIL PROTECTED]
Ops, ignore the part "ip2long() returns a string."
------------------------------------------------------------------------
[2007-12-28 14:45:19] [EMAIL PROTECTED]
ip2long() returns a string. Converting this value to float for obtain
large precision, you will have the expected result.
$ip = "213.10.212.144";
$ipaddr = sprintf("%u", ip2long($ip));
$address = sprintf("IP ADDR = %u", (float) $ipaddr);
var_dump(PHP_INT_MAX, ip2long($ip), $ipaddr, $address);
--
int(2147483647)
int(-720710512)
string(10) "3574256784"
string(20) "IP ADDR = 3574256784"
------------------------------------------------------------------------
[2007-12-27 16:24:54] yardgnomeray at gmail dot com
Description:
------------
Using integer >= 2147483647 for a %u or %d will return 2147483647
Reproduce code:
---------------
$ip = "213.10.212.144";
$ipaddr = sprintf("%u",ip2long($ip));
$address = sprintf("IP ADDR = %u", $ipaddr);
echo $address;
Expected result:
----------------
IP ADDR = 3574256784
Actual result:
--------------
IP ADDR = 2147483647
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=43690&edit=1