|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-05-02 15:20 UTC] 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.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 12:00:01 2025 UTC |
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 />"; }