/**
* IP是否合法
* @param string $ip
* @return boolean
*/
function inspect_ip($ip,$divide='/') {
$divide = $divide ? $divide : '/';
if (is_array($ip)) {
return inspect_ip(implode($divide,$ip));
}
else if (strpos($ip,$divide)) {
list($start,$end) = explode($divide, $ip);
$pos = strrpos($start,'.');
$start_d = substr($start,$pos+1);
$c = substr($start,0,$pos+1);
$pos = strrpos($end,'.');
$end_d = substr($end,$pos+1);
$c2 = substr($end,0,$pos+1);
return inspect_ip($start) && inspect_ip($end) && $c == $c2 && $start != $end && $start_d < $end_d;
}
else if (filter_var($ip,FILTER_VALIDATE_IP)) {
return true;
}
return false;
}
判断IP4类型的IP或IP段是否合法
最新推荐文章于 2022-05-09 09:24:08 发布