Created
September 26, 2018 19:17
-
-
Save samjaninf/0e684397b8a41d2583f28149fa8db879 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // https://inkplant.com/code/ipv6-to-number | |
| <?php | |
| function ipaddress_to_ipnumber($ipaddress) { | |
| $pton = @inet_pton($ipaddress); | |
| if (!$pton) { return false; } | |
| $number = ''; | |
| foreach (unpack('C*', $pton) as $byte) { | |
| $number .= str_pad(decbin($byte), 8, '0', STR_PAD_LEFT); | |
| } | |
| return base_convert(ltrim($number, '0'), 2, 10); | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment