NYCPHP Meetup

NYPHP.org

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

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


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

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

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 ] );
  }
}

-c

-- 
  cmerlo at ncc.edu             http://turing.matcmp.ncc.edu/~cmerlo

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