Punycode
in package
Punycode implementation as described in RFC 3492
Tags
Table of Contents
Constants
- BASE = 36
- Bootstring parameter values
- DAMP = 700
- DELIMITER = '-'
- IDNA_ERROR_BIDI = 2048
- IDNA_ERROR_CONTEXTJ = 4096
- IDNA_ERROR_DISALLOWED = 128
- IDNA_ERROR_DOMAIN_NAME_TOO_LONG = 4
- IDNA_ERROR_EMPTY_LABEL = 1
- IDNA Error constants
- IDNA_ERROR_HYPHEN_3_4 = 32
- IDNA_ERROR_INVALID_ACE_LABEL = 1024
- IDNA_ERROR_LABEL_HAS_DOT = 512
- IDNA_ERROR_LABEL_TOO_LONG = 2
- IDNA_ERROR_LEADING_COMBINING_MARK = 64
- IDNA_ERROR_LEADING_HYPHEN = 8
- IDNA_ERROR_PUNYCODE = 256
- IDNA_ERROR_TRAILING_HYPHEN = 16
- INITIAL_BIAS = 72
- INITIAL_N = 128
- PREFIX = 'xn--'
- SKEW = 38
- TMAX = 26
- TMIN = 1
Properties
- $decodeTable : mixed
- Decode table
- $encodeTable : mixed
- Encode table
- $encoding : mixed
- Character encoding
- $nonTransitional : mixed
- Whether to use Non-Transitional Processing.
- $std3 : mixed
- Whether to use STD3 ASCII rules.
Methods
- __construct() : mixed
- Constructor
- decode() : string|bool
- Decode a Punycode domain name to its Unicode counterpart
- encode() : string|bool
- Encode a domain to its Punycode version
- useNonTransitional() : void
- Enable/disable Non-Transitional Processing
- useStd3() : void
- Enable/disable STD3 ASCII rules
- adapt() : int
- Bias adaptation
- calculateThreshold() : int
- Calculate the bias threshold to fall between TMIN and TMAX
- charToCodePoint() : int
- Convert a single or multi-byte character to its code point
- codePointToChar() : string
- Convert a code point to its single or multi-byte character
- decodePart() : string|bool
- Decode a part of domain name, such as tld
- encodePart() : string
- Encode a part of a domain name, such as tld, to its Punycode version
- listCodePoints() : array<string|int, mixed>
- List code points for a given input
- preprocess() : string
- Prepare domain name string for Punycode processing.
- validateLabel() : int
- Validates an individual part of a domain name.
Constants
BASE
Bootstring parameter values
public
mixed
BASE
= 36
DAMP
public
mixed
DAMP
= 700
DELIMITER
public
mixed
DELIMITER
= '-'
IDNA_ERROR_BIDI
public
mixed
IDNA_ERROR_BIDI
= 2048
IDNA_ERROR_CONTEXTJ
public
mixed
IDNA_ERROR_CONTEXTJ
= 4096
IDNA_ERROR_DISALLOWED
public
mixed
IDNA_ERROR_DISALLOWED
= 128
IDNA_ERROR_DOMAIN_NAME_TOO_LONG
public
mixed
IDNA_ERROR_DOMAIN_NAME_TOO_LONG
= 4
IDNA_ERROR_EMPTY_LABEL
IDNA Error constants
public
mixed
IDNA_ERROR_EMPTY_LABEL
= 1
IDNA_ERROR_HYPHEN_3_4
public
mixed
IDNA_ERROR_HYPHEN_3_4
= 32
IDNA_ERROR_INVALID_ACE_LABEL
public
mixed
IDNA_ERROR_INVALID_ACE_LABEL
= 1024
IDNA_ERROR_LABEL_HAS_DOT
public
mixed
IDNA_ERROR_LABEL_HAS_DOT
= 512
IDNA_ERROR_LABEL_TOO_LONG
public
mixed
IDNA_ERROR_LABEL_TOO_LONG
= 2
IDNA_ERROR_LEADING_COMBINING_MARK
public
mixed
IDNA_ERROR_LEADING_COMBINING_MARK
= 64
IDNA_ERROR_LEADING_HYPHEN
public
mixed
IDNA_ERROR_LEADING_HYPHEN
= 8
IDNA_ERROR_PUNYCODE
public
mixed
IDNA_ERROR_PUNYCODE
= 256
IDNA_ERROR_TRAILING_HYPHEN
public
mixed
IDNA_ERROR_TRAILING_HYPHEN
= 16
INITIAL_BIAS
public
mixed
INITIAL_BIAS
= 72
INITIAL_N
public
mixed
INITIAL_N
= 128
PREFIX
public
mixed
PREFIX
= 'xn--'
SKEW
public
mixed
SKEW
= 38
TMAX
public
mixed
TMAX
= 26
TMIN
public
mixed
TMIN
= 1
Properties
$decodeTable
Decode table
protected
static mixed
$decodeTable
= ['a' => 0, 'b' => 1, 'c' => 2, 'd' => 3, 'e' => 4, 'f' => 5, 'g' => 6, 'h' => 7, 'i' => 8, 'j' => 9, 'k' => 10, 'l' => 11, 'm' => 12, 'n' => 13, 'o' => 14, 'p' => 15, 'q' => 16, 'r' => 17, 's' => 18, 't' => 19, 'u' => 20, 'v' => 21, 'w' => 22, 'x' => 23, 'y' => 24, 'z' => 25, '0' => 26, '1' => 27, '2' => 28, '3' => 29, '4' => 30, '5' => 31, '6' => 32, '7' => 33, '8' => 34, '9' => 35]
$encodeTable
Encode table
protected
static mixed
$encodeTable
= ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
$encoding
Character encoding
protected
mixed
$encoding
$nonTransitional
Whether to use Non-Transitional Processing.
protected
mixed
$nonTransitional
= false
Setting this to true breaks backward compatibility with IDNA2003.
$std3
Whether to use STD3 ASCII rules.
protected
mixed
$std3
= false
Methods
__construct()
Constructor
public
__construct([string $encoding = 'UTF-8' ]) : mixed
Parameters
- $encoding : string = 'UTF-8'
-
Character encoding
decode()
Decode a Punycode domain name to its Unicode counterpart
public
decode(string $input) : string|bool
Parameters
- $input : string
-
Domain name in Punycode
Return values
string|bool —Unicode domain name
encode()
Encode a domain to its Punycode version
public
encode(string $input) : string|bool
Parameters
- $input : string
-
Domain name in Unicode to be encoded
Return values
string|bool —Punycode representation in ASCII
useNonTransitional()
Enable/disable Non-Transitional Processing
public
useNonTransitional(bool $nonTransitional) : void
Parameters
- $nonTransitional : bool
-
Whether to use Non-Transitional Processing
useStd3()
Enable/disable STD3 ASCII rules
public
useStd3(bool $std3) : void
Parameters
- $std3 : bool
-
Whether to use STD3 ASCII rules
adapt()
Bias adaptation
protected
adapt(int $delta, int $numPoints, bool $firstTime) : int
Parameters
- $delta : int
- $numPoints : int
- $firstTime : bool
Return values
intcalculateThreshold()
Calculate the bias threshold to fall between TMIN and TMAX
protected
calculateThreshold(int $k, int $bias) : int
Parameters
- $k : int
- $bias : int
Return values
intcharToCodePoint()
Convert a single or multi-byte character to its code point
protected
charToCodePoint(string $char) : int
Parameters
- $char : string
Return values
intcodePointToChar()
Convert a code point to its single or multi-byte character
protected
codePointToChar(int $code) : string
Parameters
- $code : int
Return values
stringdecodePart()
Decode a part of domain name, such as tld
protected
decodePart(string $input) : string|bool
Parameters
- $input : string
-
Part of a domain name
Return values
string|bool —Unicode domain part
encodePart()
Encode a part of a domain name, such as tld, to its Punycode version
protected
encodePart(string $input) : string
Parameters
- $input : string
-
Part of a domain name
Return values
string —Punycode representation of a domain part
listCodePoints()
List code points for a given input
protected
listCodePoints(string $input) : array<string|int, mixed>
Parameters
- $input : string
Return values
array<string|int, mixed> —Multi-dimension array with basic, non-basic and aggregated code points
preprocess()
Prepare domain name string for Punycode processing.
protected
preprocess(string $domain[, array<string|int, mixed> &$errors = [] ]) : string
See https://www.unicode.org/reports/tr46/#Processing
Parameters
- $domain : string
-
A domain name
- $errors : array<string|int, mixed> = []
-
Will record any errors encountered during preprocessing
Return values
stringvalidateLabel()
Validates an individual part of a domain name.
protected
validateLabel(string $label[, bool $toPunycode = true ]) : int
Parameters
- $label : string
-
Individual part of a domain name.
- $toPunycode : bool = true
-
True for encoding to Punycode, false for decoding.
Return values
int —0 if valid, otherwise an int matching a defined const.