[nycphp-talk] I need a function that will compare IP addresses

Christopher R. Merlo cmerlo at
Thu Aug 21 12:07:48 EDT 2003

On 2003-08-15 01:29 -0400, Phil Powell <soazine at> wrote:

>    Is there an existing function out there that can do this? I want to
>    compare "" with "" and come with as a "match", or
>    "" with "", but no "match if "" and
>    "".

This'll work:

function ipmatch ( $ip1, $ip2 ) {
  if( ereg( "(([0-9]{1,3}\.){3})[0-9]{1,3}", $ip1, $match1 ) &&
      ereg( "(([0-9]{1,3}\.){3})[0-9]{1,3}", $ip2, $match2 ) ) {
    return( $match1[ 1 ] == $match2[ 1 ] );


  cmerlo at   

Q: How many Microsoft support staff does it take to change a light bulb?
A: Four. One to ask "What is the registration number of the light bulb?",
   one to ask "Have you tried rebooting it?", another to ask "Have you
   tried reinstalling it?" and the last one to say "It must be your hardware
   because the light bulb in our office works fine..."

More information about the talk mailing list