Documentation

Ipv6
in package

FinalYes

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
split_v6_v4()  : array<string|int, string>
Splits an IPv6 address into the IPv6 and IPv4 representation parts

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
see
Ipv6::uncompress()
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
author

Alexander Merz alexander.merz@web.de

author

elfrink at introweb dot nl

author

Josh Peck

copyright

2003-2005 The PHP Group

license

https://opensource.org/licenses/bsd-license.php

throws
InvalidArgument

When the passed argument is not a string or a stringable object.

Return values
string

The uncompressed IPv6 address

split_v6_v4()

Splits an IPv6 address into the IPv6 and IPv4 representation parts

private static split_v6_v4(string $ip) : array<string|int, string>

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

Return values
array<string|int, string>

[0] contains the IPv6 represented part, and [1] the IPv4 represented part


        
On this page

Search results