private function IP2Location::ipv6ToLong in Smart IP 6
Same name and namespace in other branches
- 7 includes/IP2Location.inc \IP2Location::ipv6ToLong()
1 call to IP2Location::ipv6ToLong()
- IP2Location::lookup in includes/
IP2Location.inc
File
- includes/
IP2Location.inc, line 278
Class
Code
private function ipv6ToLong($ip) {
$n = substr_count($ip, ':');
if ($n < 7) {
$expanded = '::';
while ($n < 7) {
$expanded .= ':';
$n++;
}
$ip = preg_replace('/::/', $expanded, $ip);
}
$subLoc = 8;
$ipv6No = '0';
foreach (preg_split('/:/', $ip) as $ipSub) {
$subLoc--;
if ($ipSub == '') {
continue;
}
$ipv6No = bcadd($ipv6No, bcmul(hexdec($ipSub), bcpow(hexdec('0x10000'), $subLoc)));
}
return $ipv6No;
}