标签:
$ip = ‘192.168.6.1‘; $mask = ‘255.255.2.0‘; $sub_net = array();//子网 $ip_explode = explode(‘.‘, $ip); $mask_explode = explode(‘.‘, $mask); foreach ($ip_explode as $key => $ip_num) { //10进制转2进制 $a = decbin($ip_num); $b = decbin($mask_explode[$key]); //补0补够8位 $a = sprintf("%08d", $a); $b = sprintf("%04d", $b);//前补0 $b = sprintf("%0.4f", $b);//后取多少位 echo $a."==".$b."\n"; $c = $a & $b; echo $c."\n"; $d = bindec($c); echo $d."\n"; $sub_net[] = $d; } $sub_net = implode(‘.‘, $sub_net); echo $sub_net;
标签:
原文地址:http://www.cnblogs.com/jdhu/p/4246228.html