note 71957 modified in function.ip2long by danbrown
| From: | danbrown@php.net | Date: | Fri, 05 Dec 2008 13:46:04 +0000 |
| Subject: | note 71957 modified in function.ip2long by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-147703@lists.php.net to get a copy of this message | ||
Convert an ipv6 address to an base 10 integer
<?php
function ip2long6($ip)
{
if (substr_count($ip, '::'))
{
$ip = str_replace('::', str_repeat(':0000', 8 - substr_count($ip,
':')) . ':', $ip) ;
}
$ip = explode(':', $ip) ;
$r_ip = '' ;
foreach ($ip as $v)
{
$r_ip .= str_pad(base_convert($v, 16, 2), 16, 0, STR_PAD_LEFT) ;
}
return base_convert($r_ip, 2, 10) ;
}
?>
--was--
Convert an ipv6 address to an base 10 integer
function ip2long6($ip)
{
if (substr_count($ip, '::'))
{
$ip = str_replace('::', str_repeat(':0000', 8 - substr_count($ip,
':')) . ':', $ip) ;
}
$ip = explode(':', $ip) ;
$r_ip = '' ;
foreach ($ip as $v)
{
$r_ip .= str_pad(base_convert($v, 16, 2), 16, 0, STR_PAD_LEFT) ;
}
return base_convert($r_ip, 2, 10) ;
}
http://php.net/manual/en/function.ip2long.php