Class to validate and to work with IPv6 addresses

This was originally based on the PEAR class of the same name, but has been entirely rewritten.

package Requests
subpackage Utilities

 Methods

Checks an IPv6 address

check_ipv6(string $ip) : boolean
Static

Checks if the given IP is a valid IPv6 address

Parameters

$ip

string

An IPv6 address

Returns

booleantrue if $ip is a valid IPv6 address

Compresses an IPv6 address

compress(string $ip) : string
Static

RFC 4291 allows you to compress consecutive 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

Parameters

$ip

string

An IPv6 address

Returns

stringThe compressed IPv6 address

Uncompresses an IPv6 address

uncompress(string $ip) : string
Static

RFC 4291 allows you to compress consecutive zero pieces in an address to '::'. This method expects a valid IPv6 address and expands the '::' to the required number of zero pieces.

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

author Alexander Merz
author elfrink at introweb dot nl
author Josh Peck
copyright 2003-2005 The PHP Group
license http://www.opensource.org/licenses/bsd-license.php

Parameters

$ip

string

An IPv6 address

Returns

stringThe uncompressed IPv6 address

Splits an IPv6 address into the IPv6 and IPv4 representation parts

split_v6_v4(string $ip) : array<mixed,string>
Static

RFC 4291 allows you to represent the last two parts of an IPv6 address using the standard IPv4 representation

Example: 0:0:0:0:0:0:13.1.68.3 0:0:0:0:0:FFFF:129.144.52.38

Parameters

$ip

string

An IPv6 address

Returns

array<mixed,string>[0] contains the IPv6 represented part, and [1] the IPv4 represented part