本文整理匯總了PHP中IP::getVersion方法的典型用法代碼示例。如果您正苦於以下問題:PHP IP::getVersion方法的具體用法?PHP IP::getVersion怎麽用?PHP IP::getVersion使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類IP
的用法示例。
在下文中一共展示了IP::getVersion方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getHostsCount
/**
* @return number|string
*/
public function getHostsCount()
{
$blockSize = $this->getBlockSize();
if ($this->ip->getVersion() === IP::IP_V4) {
return $blockSize > 2 ? $blockSize - 2 : $blockSize;
}
return $blockSize;
}
示例2: count
/**
* @return int
*/
public function count()
{
if ($this->firstIP->getVersion() === IP::IP_V4) {
$count = $this->lastIP->toLong() - $this->firstIP->toLong();
} else {
$count = bcsub($this->lastIP->toLong(), $this->firstIP->toLong());
}
return $count;
}
示例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;
}