本文整理汇总了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;
}