interface TransliterationInterface (View source)

Defines an interface for classes providing transliteration.

Methods

string
removeDiacritics(string $string)

Removes diacritics (accents) from certain letters.

string
transliterate(string $string, string $langcode = 'en', string $unknown_character = '?', int $max_length = NULL)

Transliterates text from Unicode to US-ASCII.

Details

string removeDiacritics(string $string)

Removes diacritics (accents) from certain letters.

This only applies to certain letters: Accented Latin characters like a-with-acute-accent, in the UTF-8 character range of 0xE0 to 0xE6 and 01CD to 024F. Replacements that would result in the string changing length are excluded, as well as characters that are not accented US-ASCII letters.

Parameters

string $string

The string holding diacritics.

Return Value

string

$string with accented letters replaced by their unaccented equivalents.

string transliterate(string $string, string $langcode = 'en', string $unknown_character = '?', int $max_length = NULL)

Transliterates text from Unicode to US-ASCII.

Parameters

string $string

The string to transliterate.

string $langcode

(optional) The language code of the language the string is in. Defaults to 'en' if not provided. Warning: this can be unfiltered user input.

string $unknown_character

(optional) The character to substitute for characters in $string without transliterated equivalents. Defaults to '?'.

int $max_length

(optional) If provided, return at most this many characters, ensuring that the transliteration does not split in the middle of an input character's transliteration.

Return Value

string

$string with non-US-ASCII characters transliterated to US-ASCII characters, and unknown characters replaced with $unknown_character.