Encoding

Conversions between UTF-8, Latin1, UTF-16BE and hexadecimal byte strings.

Namespace: Com\Tecnick\Unicode\Convert

File: Encoding.php line 36

Conversions between UTF-8, Latin1, UTF-16BE and hexadecimal byte strings.

Tags

Methods

hexToStr()

File: Encoding.php line 104

public hexToStr(string $hex) : string

Pairs of characters that are not hexadecimal digits are converted to a NUL byte. An odd number of digits is completed with a trailing zero, as the last digit of the final byte.

Parameters

  • $hex : string: Hex code to convert

Return values

string

latinArrToStr()

File: Encoding.php line 81

public latinArrToStr(array<string|int, int<0, 255>> $latarr) : string

Parameters

  • $latarr : array<string|int, int<0, 255»: Array of Latin1 code points

Return values

string

strToHex()

File: Encoding.php line 91

public strToHex(string $str) : string

Parameters

  • $str : string: String to convert

Return values

string

toUTF16BE()

File: Encoding.php line 154

public toUTF16BE(string $str) : string

Parameters

  • $str : string: UTF-8 String to convert

Return values

string —

UTF-16BE encoded string

toUTF8()

File: Encoding.php line 132

public toUTF8(string $str[, null|string|array<string|int, string> $enc = null ]) : string

Parameters

  • $str : string: String to convert
  • $enc : null|string|array<string|int, string> = null: Array or comma separated list string of encodings

Return values

string —

UTF-8 encoded string

uniArrToLatinArr()

File: Encoding.php line 48

public uniArrToLatinArr(array<string|int, int> $ordarr) : array<string|int, int>

A code point that has no Latin1 counterpart is replaced with ‘?’, except U+FFFD REPLACEMENT CHARACTER, which is dropped: the returned array is then shorter than the input one.

Parameters

  • $ordarr : array<string|int, int>: Array containing UTF-8 code points

Return values

array<string|int, int> —

Array containing Latin1 code points