本文整理匯總了PHP中IP::toUnsigned6方法的典型用法代碼示例。如果您正苦於以下問題:PHP IP::toUnsigned6方法的具體用法?PHP IP::toUnsigned6怎麽用?PHP IP::toUnsigned6使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類IP
的用法示例。
在下文中一共展示了IP::toUnsigned6方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: normaliseRange
/**
* Gets rid of uneeded numbers in quad-dotted/octet IP strings
* For example, 127.111.113.151/24 -> 127.111.113.0/24
*/
static function normaliseRange($range)
{
$parts = explode('/', $range);
if (count($parts) == 2) {
// IPv6
if (IP::isIPv6($range) && $parts[1] >= 64 && $parts[1] <= 128) {
$bits = $parts[1];
$ipint = IP::toUnsigned6($parts[0]);
# Native 32 bit functions WONT work here!!!
# Convert to a padded binary number
$network = wfBaseConvert($ipint, 10, 2, 128);
# Truncate the last (128-$bits) bits and replace them with zeros
$network = str_pad(substr($network, 0, $bits), 128, 0, STR_PAD_RIGHT);
# Convert back to an integer
$network = wfBaseConvert($network, 2, 10);
# Reform octet address
$newip = IP::toOctet($network);
$range = "{$newip}/{$parts[1]}";
} else {
if (IP::isIPv4($range) && $parts[1] >= 16 && $parts[1] <= 32) {
$shift = 32 - $parts[1];
$ipint = IP::toUnsigned($parts[0]);
$ipint = $ipint >> $shift << $shift;
$newip = long2ip($ipint);
$range = "{$newip}/{$parts[1]}";
}
}
}
return $range;
}