Edit report at https://bugs.php.net/bug.php?id=44892&edit=1
ID: 44892 Comment by: patrick_adrichem at hotmail dot com Reported by: anthony dot morris at bankofamerica dot com Summary: IP2LONG doesn't handle leading zeroes Status: Not a bug Type: Bug Package: Network related Operating System: Multiple PHP Version: 5.2.6 Block user comment: N Private report: N New Comment: What about 02.123.123.123? that should be in octal still 2 right? it returns false. <?php $aIpAddresses = array("2.123.123.123", "102.123.123.123", "202.123.123.123"); foreach ($aIpAddresses as $sIpAddress) { echo "Ip: ",$sIpAddress,PHP_EOL,"<br />", "Long: ",var_export(ip2long($sIpAddress), true),PHP_EOL,"<br />"; $aIpAddress = explode(".", $sIpAddress); $aIpAddress[0] = substr($aIpAddress[0], -2); $sIpAddress = implode(".", $aIpAddress); echo "Ip no int: ",var_export(ip2long($sIpAddress), true),PHP_EOL,"<br />"; $aIpAddress[0] = (int) $aIpAddress[0]; $sIpAddress = implode(".", $aIpAddress); echo "Ip int: ",var_export(ip2long($sIpAddress), true),PHP_EOL,PHP_EOL,"<br /><br />"; } Previous Comments: ------------------------------------------------------------------------ [2008-05-02 15:54:31] fel...@php.net That is expected. "All numbers supplied as parts in IPv4 dotted decimal notation may be decimal, octal, or hexadecimal, as specified in the ISO C standard (that is, a leading 0x or 0X implies hexadecimal; otherwise, a leading '0' implies octal; otherwise, the number is interpreted as decimal)." - http://www.opengroup.org/onlinepubs/000095399/functions/inet_addr.html ------------------------------------------------------------------------ [2008-05-02 15:20:48] anthony dot morris at bankofamerica dot com Description: ------------ IP2Long does not handle leading zeroes Reproduce code: --------------- <?PHP echo LONG2IP(IP2LONG('192.068.068.068')); ?> OR <?PHP echo IP2LONG('192.068.068.068'); echo '<br>'; echo IP2LONG('192.68.68.68'); ?> Expected result: ---------------- Notice the top example should return back the same IP. The bottom example, should produce the same LONG number. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=44892&edit=1