ID:               43690
 Updated by:       [EMAIL PROTECTED]
 Reported By:      yardgnomeray at gmail dot com
-Status:           Open
+Status:           Bogus
 Bug Type:         Strings related
 Operating System: Windows XP SP2
 PHP Version:      5.2.5
 New Comment:

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Nothing is wrong here:

$ip = "213.10.212.144";
var_dump(ip2long( $ip ) );

returns: int(-720710512)

$ip = "213.10.212.144";
$ipaddr = sprintf("%u",ip2long($ip));
var_dump( $ipaddr );

returns: string(10) "3574256784"

Using a string that does not fit in the integer range as a number (with
%d or %u) does not work, as the string itself is first converted to an
integer - which won't work as it doesn't fit. You shouldn't simply use
%u for the returned variable from sprintf() - as it's not a n integer,
but a string (so use %s).



Previous Comments:
------------------------------------------------------------------------

[2007-12-29 12:15:50] [EMAIL PROTECTED]

I'm using PHP 5.3.0-dev (cli) (built: Dec 25 2007 10:07:55), and the
convertion was necessary.

------------------------------------------------------------------------

[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

Reply via email to