public static function parseCidr(string $cidr): array
    {
        $pos = strpos($cidr, "/");
        if ($pos === false) {
            throw new \UnexpectedValueException(
                "invalid CIDR; missing expected '/' delimeter"
            );
        } elseif ($pos === 0) {
            throw new \UnexpectedValueException(
                "invalid CIDR; missing expected ip"
            );
        }

        $ip = substr($cidr, 0, $pos);
        if (!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
            throw new \UnexpectedValueException(
                "invalid CIDR ip; '$ip' is not a valid IPv4 address"
            );
        }

        $netmask = (int) substr($cidr, $pos + 1);
        if ($netmask < 0 || $netmask > 32) {
            throw new \UnexpectedValueException(
                "invalid CIDR network mask; expecting a value between 0 and 32"
            );
        }

        return [$ip, $netmask];
    }
public static function parseCidr(string $cidr): array
    {
        $pos = strpos($cidr, "/");
        if ($pos === false) {
            throw new \UnexpectedValueException(
                "invalid CIDR; missing expected '/' delimeter"
            );
        } elseif ($pos === 0) {
            throw new \UnexpectedValueException(
                "invalid CIDR; missing expected ip"
            );
        }

        $ip = substr($cidr, 0, $pos);
        if (!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
            throw new \UnexpectedValueException(
                "invalid CIDR ip; '$ip' is not a valid IPv4 address"
            );
        }

        $netmask = (int) substr($cidr, $pos + 1);
        if ($netmask < 0 || $netmask > 32) {
            throw new \UnexpectedValueException(
                "invalid CIDR network mask; expecting a value between 0 and 32"
            );
        }

        return [$ip, $netmask];
    }
public static function parseCidr ( string $ cidr ) : array { $ pos = strpos ( $ cidr , "/" ) ; if ( $ pos === false ) { throw new \ UnexpectedValueException ( "invalid CIDR; missing expected '/' delimeter" ) ; } elseif ( $ pos === 0 ) { throw new \ UnexpectedValueException ( "invalid CIDR; missing expected ip" ) ; } $ ip = substr ( $ cidr , 0 , $ pos ) ; if ( ! filter_var ( $ ip , FILTER_VALIDATE_IP , FILTER_FLAG_IPV4 ) ) { throw new \ UnexpectedValueException ( "invalid CIDR ip; '$ip' is not a valid IPv4 address" ) ; } $ netmask = ( int ) substr ( $ cidr , $ pos + 1 ) ; if ( $ netmask < 0 || $ netmask > 32 ) { throw new \ UnexpectedValueException ( "invalid CIDR network mask; expecting a value between 0 and 32" ) ; } return [ $ ip , $ netmask ] ; }
Parse a CIDR address range into the ip and network mask portions

@param string $cidr The ip range to parse
@return array The ip and network mask `[0 => ip, 1 => netmask]`
Parse a CIDR address range into the ip and network mask portions