Encoding

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

Namespace: Com\Tecnick\Unicode\Convert

class Encoding

Source: src/Convert/Encoding.php:36

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

Methods

hexToStr()

Convert an hexadecimal string (byte string - as in the PDF standard) to 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.

public hexToStr(string $hex): string

Parameters:

  • $hex (string): Hex code to convert

Returns: string

Source: src/Convert/Encoding.php:104

latinArrToStr()

Converts an array of Latin1 code points to a string

public latinArrToStr(int<0, 255>[] $latarr): string

Parameters:

  • $latarr (int<0, 255>[]): Array of Latin1 code points

Returns: string

Source: src/Convert/Encoding.php:81

strToHex()

Convert a string to an hexadecimal string (byte string) representation (as in the PDF standard)

public strToHex(string $str): string

Parameters:

  • $str (string): String to convert

Returns: string

Source: src/Convert/Encoding.php:91

toUTF16BE()

Converts an UTF-8 string to UTF-16BE

public toUTF16BE(string $str): string

Parameters:

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

Returns: string: UTF-16BE encoded string

Source: src/Convert/Encoding.php:154

toUTF8()

Converts a string with an unknown encoding to UTF-8

public toUTF8(string $str, null|string|string[] $enc = null): string

Parameters:

  • $str (string): String to convert
  • $enc (null|string|string[]): Array or comma separated list string of encodings

Returns: string: UTF-8 encoded string

Source: src/Convert/Encoding.php:132

uniArrToLatinArr()

Converts UTF-8 code array to Latin1 codes.

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.

public uniArrToLatinArr(int[] $ordarr): int[]

Parameters:

  • $ordarr (int[]): Array containing UTF-8 code points

Returns: int[]: Array containing Latin1 code points

Source: src/Convert/Encoding.php:48