Convert

Malformed input policy: a string or char array that is not valid UTF-8 raises an exception, while a code point that cannot be encoded (negative, surrogate or greater than U+10FFFF) is replaced with '?

Namespace: Com\Tecnick\Unicode

class Convert extends Encoding

Extends: Encoding

Source: src/Convert.php:38

Malformed input policy: a string or char array that is not valid UTF-8 raises an exception, while a code point that cannot be encoded (negative, surrogate or greater than U+10FFFF) is replaced with ‘?’.

Methods

chr()

Returns the unicode string containing the character specified by value

public chr(int $ord): string

Parameters:

  • $ord (int): Unicode character value to convert

Returns: string: Returns the unicode string

Throws:

Source: src/Convert.php:85

chrArrToOrdArr()

Converts an array of UTF-8 chars to an array of codepoints (integer values)

public chrArrToOrdArr(string[] $chars): int[]

Parameters:

  • $chars (string[]): Array of UTF-8 chars

Returns: int[]

Throws:

Source: src/Convert.php:152

getSubUniArrStr()

Extract a slice of the $uniarr array and return it as string

public getSubUniArrStr(string[] $uniarr, int $start = 0, int|null $end = null): string

Parameters:

  • $uniarr (string[]): The input array of characters
  • $start (int): The position of the starting element
  • $end (int|null): The position of the first element that will not be returned. An $end that is not after $start returns an empty string.

Returns: string

Source: src/Convert.php:228

ord()

Returns the unicode value of the specified character.

If more than one character is given, only the first codepoint is returned.

public ord(string $chr): int

Parameters:

  • $chr (string): Unicode character

Returns: int: Returns the unicode value

Throws:

Source: src/Convert.php:105

ordArrToChrArr()

Converts an array of UTF-8 code points to an array of chars

public ordArrToChrArr(int[] $ords): string[]

Parameters:

  • $ords (int[]): Array of UTF-8 code points

Returns: string[]

Throws:

Source: src/Convert.php:170

strToChrArr()

Converts an UTF-8 string to an array of UTF-8 characters

public strToChrArr(string $str): array<int,string>

Parameters:

  • $str (string): String to convert

Returns: array<int,string>

Throws:

Source: src/Convert.php:133

strToOrdArr()

Converts an UTF-8 string to an array of UTF-8 codepoints (integer values)

public strToOrdArr(string $str): int[]

Parameters:

  • $str (string): String to convert

Returns: int[]

Throws:

Source: src/Convert.php:195

Inherited members

From Encoding

  • hexToStr(): Convert an hexadecimal string (byte string - as in the PDF standard) to string.
  • latinArrToStr(): Converts an array of Latin1 code points to a string
  • strToHex(): Convert a string to an hexadecimal string (byte string) representation (as in the PDF standard)
  • toUTF16BE(): Converts an UTF-8 string to UTF-16BE
  • toUTF8(): Converts a string with an unknown encoding to UTF-8
  • uniArrToLatinArr(): Converts UTF-8 code array to Latin1 codes.