<?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 "不属于"; }
转载请注明出处 AE博客|墨渊 » PHP对比IP是否匹配或在IP段中
发表评论