<?php
function match_network ($nets, $ip) {
	foreach ($nets as $net) {
		$ip_arr	 = explode('/', $net);
		if (!$ip_arr[1])
			$ip_arr[1] = '32';

		$net_long = ip2long($ip_arr[0]);
		$x = ip2long($ip_arr[1]);
		$mask = long2ip($x) == $ip_arr[1] ? $x : 0xffffffff << (32 - $ip_arr[1]);
		$ip_long = ip2long($ip);

		if (($ip_long & $mask) == ($net_long & $mask)) return true;
	}
	return false;
}
?>