SDK for PHP V3

Idna
in package

FinalYes

Converts internationalized hosts to their ASCII form.

Table of Contents

Methods

toAscii()  : string
Returns the ASCII form of a URI host.
uriFor()  : UriInterface
Returns a URI for a string whose host may be internationalized.

Methods

toAscii()

Returns the ASCII form of a URI host.

public static toAscii(string $host[, int|null $options = null ]) : string

A host with no non-ASCII data, raw or percent-encoded, is returned unchanged. Any other host is converted to A-labels with the UTS #46 ToASCII operation, by default non-transitionally and with the STD3 ASCII rules and the bidi and joiner checks. $options replaces that default with IDNA_* constants. Whatever the options, a converted host must be a valid ASCII host that is neither bracketed nor percent-encoded.

Conversion maps characters, so fullwidth digits can become an IPv4 address. Apply any destination policy to the returned host, not to the input.

Parameters
$host : string
$options : int|null = null
Tags
throws
InvalidArgumentException

If the host cannot be converted or decodes to more than 1024 characters.

throws
RuntimeException

If the intl extension is not available.

see
https://www.unicode.org/reports/tr46/#ToASCII
Return values
string

uriFor()

Returns a URI for a string whose host may be internationalized.

public static uriFor(string $uri[, int|null $options = null ]) : UriInterface

The string is parsed exactly as new Uri($uri) parses it, except that a host containing non-ASCII data is converted with toAscii() and the given $options.

Parameters
$uri : string
$options : int|null = null
Tags
throws
MalformedUriException

If the URI cannot be parsed or its host cannot be converted.

throws
RuntimeException

If the intl extension is not available.

Return values
UriInterface
<-- modeled_exceptions -->
On this page