(int), 'end' => (int)] representing * the according start and end addresses as integer * values. Returns false on malformed input. * * @param string $cidr 192.168.101/24, 1.2.3.4/16, ... * @return array{start: int, end: int}|null start and end address, false on error */ public static function parseCidr(string $cidr): ?array { $parts = explode('/', $cidr); if (count($parts) !== 2) { $ip = ip2long($cidr); if ($ip === false) return null; return ['start' => $ip, 'end' => $ip]; } $ip = $parts[0]; $bits = $parts[1]; if (!is_numeric($bits) || $bits < 0 || $bits > 32) return null; $dots = substr_count($ip, '.'); if ($dots < 3) { $ip .= str_repeat('.0', 3 - $dots); } $ip = ip2long($ip); if ($ip === false) return null; $bits = (int)((2 ** (32 - $bits)) - 1); return ['start' => $ip & ~$bits, 'end' => $ip | $bits]; } }