|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2015-11-03 16:28 UTC] raffaellobertini at gmail dot com
Description:
------------
just run ip2long('195.194.213.096') it will return false instead of
interpreting the string as '195,194.213.96'
if you point me to the code i fix myself. I mean, the function is not robust.
cannot crash for a number that is '096' that it will be 96 as integer.
Test script:
---------------
ip2long('195.194.213.096') === ip2long('195,194.213.96')
//anyway the code to convert into packed format is quite easy, but It is not nice that I cannot rely on php built in function....
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 10:00:01 2025 UTC |
@cmb@php.net you are perfectly right! I would like to suggest (raw idea), instead of changing ip2long(), to built-in another helper function instead, that process the IP in string format and "clean" it and make it concise. it will be something like: function ip_clean(string $ip) : ?string { ... } and just process splitting by dot returning in a "correct" format the string to be processed further if required.ip_clean() could be easily implemented in userland, though, for instance: <?php function ip_clean(string $ip) : ?string { return implode( '.', array_map( function ($el) { return (int) $el; }, explode('.', $ip) ) ); } See <https://3v4l.org/NcNg7>.