public function PHPTransliteration::transliterate

Implements TransliterationInterface::transliterate().

Overrides TransliterationInterface::transliterate

File

drupal/core/lib/Drupal/Component/Transliteration/PHPTransliteration.php, line 81
Definition of \Drupal\Component\Transliteration\PHPTransliteration.

Class

PHPTransliteration
Implements transliteration without using the PECL extensions.

Namespace

Drupal\Component\Transliteration

Code

public function transliterate($string, $langcode = 'en', $unknown_character = '?') {
  $result = '';

  // Split into Unicode characters and transliterate each one.
  foreach (preg_split('//u', $string, 0, PREG_SPLIT_NO_EMPTY) as $character) {
    $code = self::ordUTF8($character);
    if ($code == -1) {
      $result .= $unknown_character;
    }
    else {
      $result .= $this
        ->replace($code, $langcode, $unknown_character);
    }
  }
  return $result;
}