3v4l.org

run code in 300+ PHP versions simultaneously
<?php function cidr_match($ip, $range){ list ($subnet, $bits) = explode('/', $range); if ($bits === null) { $bits = 32; } $ip = ip2long($ip); $subnet = ip2long($subnet); $mask = -1 << (32 - $bits); $subnet &= $mask; # nb: in case the supplied subnet wasn't correctly aligned return ($ip & $mask) == $subnet; } var_dump(cidr_match('79.142.17.1', '79.142.16.0/20')); var_dump(cidr_match('79.142.35.4', '79.142.16.0/20'));

preferences:
84.59 ms | 406 KiB | 5 Q