|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-12-27 16:24 UTC] 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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 21:00:01 2025 UTC |
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"@felipe... you're wrong here - this works just fine without having to cast to float: derick@kossu:~$ 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