本文整理汇总了PHP中IP::parseBin方法的典型用法代码示例。如果您正苦于以下问题:PHP IP::parseBin方法的具体用法?PHP IP::parseBin怎么用?PHP IP::parseBin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IP
的用法示例。
在下文中一共展示了IP::parseBin方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getSpanNetwork
/**
* @return Network
*/
public function getSpanNetwork()
{
$xorIP = IP::parseInAddr($this->getFirstIP()->inAddr() ^ $this->getLastIP()->inAddr());
preg_match('/^(0*)/', $xorIP->toBin(), $match);
$prefixLength = strlen($match[1]);
$ip = IP::parseBin(str_pad(substr($this->getFirstIP()->toBin(), 0, $prefixLength), $xorIP->getMaxPrefixLength(), '0'));
return new Network($ip, Network::prefix2netmask($prefixLength, $ip->getVersion()));
}
示例2: getLastHost
/**
* @return IP
*/
public function getLastHost()
{
$broadcast = $this->getBroadcast();
if ($broadcast->getVersion() === IP::IP_V4) {
if ($this->getBlockSize() > 2) {
return IP::parseBin(substr($broadcast->toBin(), 0, $broadcast->getMaxPrefixLength() - 1) . '0');
}
}
return $broadcast;
}
示例3: getHosts
/**
* @return Range
*/
public function getHosts()
{
$firstHost = $this->getNetwork();
$lastHost = $this->getBroadcast();
if ($this->ip->getVersion() === IP::IP_V4) {
if ($this->getBlockSize() > 2) {
$firstHost = IP::parseBin(substr($firstHost->toBin(), 0, $firstHost->getMaxPrefixLength() - 1) . '1');
$lastHost = IP::parseBin(substr($lastHost->toBin(), 0, $lastHost->getMaxPrefixLength() - 1) . '0');
}
}
return new Range($firstHost, $lastHost);
}