本文整理匯總了PHP中IP::getMaxPrefixLength方法的典型用法代碼示例。如果您正苦於以下問題:PHP IP::getMaxPrefixLength方法的具體用法?PHP IP::getMaxPrefixLength怎麽用?PHP IP::getMaxPrefixLength使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類IP
的用法示例。
在下文中一共展示了IP::getMaxPrefixLength方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getBlockSize
/**
* @param bool $largeNumber
* @return number|string
*/
public function getBlockSize($largeNumber = false)
{
$maxPrefixLength = $this->ip->getMaxPrefixLength();
$prefixLength = $this->getPrefixLength();
if ($largeNumber) {
return bcpow('2', (string) ($maxPrefixLength - $prefixLength));
}
return pow(2, $maxPrefixLength - $prefixLength);
}
示例2: getBlockSize
/**
* @param bool $largeNumber
* @return number|string
*/
public function getBlockSize()
{
$maxPrefixLength = $this->ip->getMaxPrefixLength();
$prefixLength = $this->getPrefixLength();
if ($this->ip->getVersion() === IP::IP_V6) {
return bcpow('2', (string) ($maxPrefixLength - $prefixLength));
}
return pow(2, $maxPrefixLength - $prefixLength);
}
示例3: moveTo
/**
* @param int $prefixLength
* @return array
* @throws \Exception
*/
public function moveTo($prefixLength)
{
$maxPrefixLength = $this->ip->getMaxPrefixLength();
if ($prefixLength <= $this->getPrefixLength() || $prefixLength > $maxPrefixLength) {
throw new \Exception('Invalid prefix length ');
}
$netmask = self::prefix2netmask($prefixLength, $this->ip->getVersion());
$networks = array();
$subnet = clone $this;
$subnet->setPrefixLength($prefixLength);
while ($subnet->ip->inAddr() <= $this->getLastIP()->inAddr()) {
$networks[] = $subnet;
$subnet = new self($subnet->getLastIP()->next(), $netmask);
}
return $networks;
}