用PHP判断IP是否相匹配,或者是否在一个IP段里

用PHP判断IP是否相匹配,或者是否在一个IP段里


<?php

$ip1 = "192.168.10.1";

$ip2 = "192.168.10.1";

$ips = "192.168.10.*";

if (strcmp($ip1, $ip2) == 0) {

    echo "相等";

} else {

    echo "不相等";

}

$ip1_segment = substr($ip1, 0, strrpos($ip1, '.'));//截取网段    

$ips_segment = substr($ips, 0, strrpos($ip1,'.'));//截取网段    

if(strcmp($ip1_segment,$ips_segment) == 0){//比较   

echo "属于";  

}else{   

echo "不属于";  

}