Converter
in package
FinalYes
Table of Contents
Constants
- IPV4_MAPPED_PREFIX = '::ffff:'
- IPV6_6TO4_PREFIX = '2002:'
- REGEXP_IPV4_HOST = '/ (?(DEFINE) # . is missing as it is used to separate labels (?<hexadecimal>0x[[:xdigit:]]*) (?<octal>0[0-7]*) (?<decimal>\d+) (?<ipv4_part>(?:(?&hexadecimal)|(?&octal)|(?&decimal))*) ) ^(?:(?&ipv4_part)\.){0,3}(?&ipv4_part)\.?$ /x'
- REGEXP_IPV4_NUMBER_PER_BASE = ['/^0x(?<number>[[:xdigit:]]*)$/' => 16, '/^0(?<number>[0-7]*)$/' => 8, '/^(?<number>\d+)$/' => 10]
Properties
- $calculator : Calculator
- $maxIPv4Number : mixed
Methods
- __construct() : mixed
- fromBCMath() : self
- Returns an instance using a Bcmath calculator.
- fromEnvironment() : self
- Returns an instance using a detected calculator depending on the PHP environment.
- fromGMP() : self
- Returns an instance using a GMP calculator.
- fromNative() : self
- Returns an instance using a PHP native calculator (requires 64bits PHP).
- isIpv4() : bool
- toDecimal() : string|null
- Tries to convert a IPv4 hexadecimal or a IPv4 octal notation into a IPv4 dot-decimal notation if possible otherwise returns null.
- toHexadecimal() : string|null
- toIPv6Using6to4() : string|null
- toIPv6UsingMapping() : string|null
- toOctal() : string|null
- labelToNumber() : mixed
- Converts a domain label into a IPv4 integer part.
- long2Ip() : string
- Generates the dot-decimal notation for IPv4.
Constants
IPV4_MAPPED_PREFIX
private
mixed
IPV4_MAPPED_PREFIX
= '::ffff:'
IPV6_6TO4_PREFIX
private
mixed
IPV6_6TO4_PREFIX
= '2002:'
REGEXP_IPV4_HOST
private
mixed
REGEXP_IPV4_HOST
= '/
(?(DEFINE) # . is missing as it is used to separate labels
(?<hexadecimal>0x[[:xdigit:]]*)
(?<octal>0[0-7]*)
(?<decimal>\d+)
(?<ipv4_part>(?:(?&hexadecimal)|(?&octal)|(?&decimal))*)
)
^(?:(?&ipv4_part)\.){0,3}(?&ipv4_part)\.?$
/x'
REGEXP_IPV4_NUMBER_PER_BASE
private
mixed
REGEXP_IPV4_NUMBER_PER_BASE
= ['/^0x(?<number>[[:xdigit:]]*)$/' => 16, '/^0(?<number>[0-7]*)$/' => 8, '/^(?<number>\d+)$/' => 10]
Properties
$calculator read-only
private
Calculator
$calculator
$maxIPv4Number read-only
private
mixed
$maxIPv4Number
Methods
__construct()
public
__construct(Calculator $calculator) : mixed
Parameters
- $calculator : Calculator
fromBCMath()
Returns an instance using a Bcmath calculator.
public
static fromBCMath() : self
Return values
selffromEnvironment()
Returns an instance using a detected calculator depending on the PHP environment.
public
static fromEnvironment() : self
Tags
Return values
selffromGMP()
Returns an instance using a GMP calculator.
public
static fromGMP() : self
Return values
selffromNative()
Returns an instance using a PHP native calculator (requires 64bits PHP).
public
static fromNative() : self
Return values
selfisIpv4()
public
isIpv4(Stringable|string|null $host) : bool
Parameters
- $host : Stringable|string|null
Return values
booltoDecimal()
Tries to convert a IPv4 hexadecimal or a IPv4 octal notation into a IPv4 dot-decimal notation if possible otherwise returns null.
public
toDecimal(Stringable|string|null $host) : string|null
Parameters
- $host : Stringable|string|null
Tags
Return values
string|nulltoHexadecimal()
public
toHexadecimal(Stringable|string|null $host) : string|null
Parameters
- $host : Stringable|string|null
Return values
string|nulltoIPv6Using6to4()
public
toIPv6Using6to4(Stringable|string|null $host) : string|null
Parameters
- $host : Stringable|string|null
Return values
string|nulltoIPv6UsingMapping()
public
toIPv6UsingMapping(Stringable|string|null $host) : string|null
Parameters
- $host : Stringable|string|null
Return values
string|nulltoOctal()
public
toOctal(Stringable|string|null $host) : string|null
Parameters
- $host : Stringable|string|null
Return values
string|nulllabelToNumber()
Converts a domain label into a IPv4 integer part.
private
labelToNumber(string $label) : mixed
Parameters
- $label : string
Tags
Return values
mixed —returns null if it cannot correctly convert the label
long2Ip()
Generates the dot-decimal notation for IPv4.
private
long2Ip(mixed $ipAddress) : string
Parameters
- $ipAddress : mixed
-
the number representation of the IPV4address