title: An optimized method to compare IP addresses with wildcards in PHP?
body: <p>Anyone know of an effective and secure method to see if this input:</p>
  
  <pre><code>$_SERVER['REMOTE_ADDR']
  </code></pre>
  
  <p>matches against something similar to this array of inconsistent filters (note that 200.100.*.* could be expressed as just 200.100.*) with wildcards indicated by *'s:</p>
  
  <pre><code>array(
    '192.168.1.*',
    '192.168.2.1*',
    '10.0.0.*',
    '200.100.*.*',
    '300.200.*',
  )
  </code></pre>
  
  <p><strong>Update</strong></p>
  
  <p>Thoughts?</p>
  
  <pre><code>foreach($instanceSettings['accessControl']['allowedIpV4Addresses'] as $ipV4Address) {
      echo 'Now checking against '.$ipV4Address.'.';
  
      // Compare each octet
      $ipV4AddressOctets = String::explode('.', $ipV4Address);
      $remoteIpV4AddressOctets = String::explode('.', $_SERVER['REMOTE_ADDR']);
      $remoteIpV4AddressIsAllowed = true;
      for($i = 0; $i &lt; Arr::size($ipV4AddressOctets); $i++) {
          echo 'Comparing '.$ipV4AddressOctets[$i].' against '.$remoteIpV4AddressOctets[$i].'.';
          if($ipV4AddressOctets[$i] != $remoteIpV4AddressOctets[$i] &amp;&amp; $ipV4AddressOctets[$i] != '*') {
              echo 'No match.';
              $remoteIpV4AddressIsAllowed = false;
              break;
          }
      }
  
      // Get out of the foreach if we've found a match
      if($remoteIpV4AddressIsAllowed) {
          break;
      }
  }
  </code></pre>