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)
			{
				if (strlen($match[0]) > $max)
				{
					$max = strlen($match[0]);
					$pos = $match[1];
				}
			}

			$ip_parts[0] = substr_replace($ip_parts[0], '::', $pos, $max);
		}

		if ($ip_parts[1] !== '')
		{
			return implode(':', $ip_parts);
		}

		return $ip_parts[0];
	}
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)
			{
				if (strlen($match[0]) > $max)
				{
					$max = strlen($match[0]);
					$pos = $match[1];
				}
			}

			$ip_parts[0] = substr_replace($ip_parts[0], '::', $pos, $max);
		}

		if ($ip_parts[1] !== '')
		{
			return implode(':', $ip_parts);
		}

		return $ip_parts[0];
	}
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 ) { if ( strlen ( $ match [ 0 ] ) > $ max ) { $ max = strlen ( $ match [ 0 ] ) ; $ pos = $ match [ 1 ] ; } } $ ip_parts [ 0 ] = substr_replace ( $ ip_parts [ 0 ] , '::' , $ pos , $ max ) ; } if ( $ ip_parts [ 1 ] !== '' ) { return implode ( ':' , $ ip_parts ) ; } return $ ip_parts [ 0 ] ; }
Compresses an IPv6 address

RFC 4291 allows you to compress concecutive zero pieces in an address to
'::'. This method expects a valid IPv6 address and compresses consecutive
zero pieces to '::'.

Example:  FF01:0:0:0:0:0:0:101   ->  FF01::101
0:0:0:0:0:0:0:1        ->  ::1

@see uncompress()
@param string $ip An IPv6 address
@return string The compressed IPv6 address
Compresses an IPv6 address