Ipv6
in package
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.
Table of Contents
Methods
- check_ipv6() : bool
- Checks an IPv6 address
- compress() : string
- Compresses an IPv6 address
- uncompress() : string
- Uncompresses an IPv6 address
Methods
check_ipv6()
Checks an IPv6 address
public
static check_ipv6(string $ip) : bool
Checks if the given IP is a valid IPv6 address
Parameters
- $ip : string
-
An IPv6 address
Return values
bool —true if $ip is a valid IPv6 address
compress()
Compresses an IPv6 address
public
static compress(string $ip) : string
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
Parameters
- $ip : string
-
An IPv6 address
Tags
Return values
string —The compressed IPv6 address
uncompress()
Uncompresses an IPv6 address
public
static uncompress(string|Stringable $ip) : string
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
Parameters
- $ip : string|Stringable
-
An IPv6 address
Tags
Return values
string —The uncompressed IPv6 address