Version: v0.8.1 - Beta.  We welcome contributors & feedback.

String.toEncoding

toEncoding($encoding) -> string

Description

Convert the string to the given $encoding scheme.

To revert the string back, use fromEncoding.

Id description example
url url-encoding/percent-encoding A%20%26%20B
html html entities (special chars only) A & B
htmlAll html entities (all characters) A & B
base64 alphanumeric binary-to-text QSAmIEI=
punycode unicode domain to ascii xn--mnchen-3ya.de
(other) See supported encodings.
$plain = 'Why "THT"?'

$plain.toEncoding('url')
//= 'Why%20%22THT%22%3F'

$plain.toEncoding('html')
//= 'Why "THT"?'

$plain.toEncoding('htmlAll')
//= 'Why "THT"?'

$plain.toEncoding('base64')
//= 'V2h5ICJUSFQiPw=='

$plain.toEncoding('Windows-1251')
//= 'Why "THT"?'

'münchen.de'.toEncoding('punycode')
//= 'xn--mnchen-3ya.de'

See Also