function compatible_ips( $ip_str1, $ip_str2, $netmask_str )
{
$netmask = ip2long( $netmask_str );
$ip1 = ip2long( $ip_str1 );
$ip2 = ip2long( $ip_str2 );
return ( $ip1 & $netmask ) == ( $ip2 & $netmask );
}
You can eliminate the first 3 lines if the addresses are already in binary form.