public static function compress($ip) { // Prepare the IP to be compressed.
// Note: Input validation is handled in the `uncompress()` method, which is the first call made in this method.
$ip = self::
uncompress($ip);
$ip_parts = self::
split_v6_v4($ip);
// Replace all leading zeros
$ip_parts[0
] =
preg_replace('/(^|:)0+([0-9])/', '\1\2',
$ip_parts[0
]);
// Find bunches of zeros
if (preg_match_all('/(?:^|:)(?:0(?::|$))+/',
$ip_parts[0
],
$matches, PREG_OFFSET_CAPTURE
)) { $max = 0;
$pos = null;
foreach ($matches[0
] as $match) { if (strlen($match[0
]) >
$max) { $max =
strlen($match[0
]);