Longman\IPTools\Ip::matchRange PHP Method

matchRange() public static method

public static matchRange ( $ip, $range )
    public static function matchRange($ip, $range)
    {
        $ipParts = explode('.', $ip);
        $rangeParts = explode('.', $range);
        $ipParts = array_filter($ipParts);
        $rangeParts = array_filter($rangeParts);
        $ipParts = array_slice($ipParts, 0, count($rangeParts));
        return implode('.', $rangeParts) === implode('.', $ipParts);
    }

Usage Example

Beispiel #1
0
 /**
  * @test
  */
 public function test_match_range()
 {
     $range = Ip::matchRange('192.168.100.', '192.168..');
     $this->assertTrue($range);
     $range = Ip::matchRange('192.168.1.200', '192.168.1.');
     $this->assertTrue($range);
     $range = Ip::matchRange('192.168.1.200', '192.168.2.');
     $this->assertFalse($range);
 }