Home >php教程 >php手册 >计算是否处在同一子网下的php脚本

计算是否处在同一子网下的php脚本

WBOY
WBOYOriginal
2016-06-13 10:22:031082browse

/*
如:192.16.1.13
与:255.255.255.0
进行,,与算,,要求出它为192.16.1.0
*/
$ip = "192.16.1.13";
echo get_net($ip,"255.255.255.0");

function get_net($ip,$hide="255.255.255.255") {
  $a = explode(".",$ip);
  $b = explode(".",$hide);

  for($i=0;$i    $r[$i] = (int)$a[$i] & (int)$b[$i];
  return join(".",$r);
}
?>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn