public static function compress($ip) { // Prepare the IP to be compressed
$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) {