You are here

function _transliteration_replace in Transliteration 7.3

Same name and namespace in other branches
  1. 5.2 transliteration.inc \_transliteration_replace()
  2. 5 transliteration.inc \_transliteration_replace()
  3. 6.3 transliteration.inc \_transliteration_replace()
  4. 6 transliteration.inc \_transliteration_replace()
  5. 6.2 transliteration.inc \_transliteration_replace()

Replaces a Unicode character using the transliteration database.

Parameters

string $ord: An ordinal Unicode character code.

string $unknown: Replacement string for characters that do not have a suitable ASCII equivalent.

string $langcode: Optional ISO 639 language code that denotes the language of the input and is used to apply language-specific variations. Defaults to the current display language.

Return value

string ASCII replacement character.

1 call to _transliteration_replace()
_transliteration_process in ./transliteration.inc
Transliterates UTF-8 encoded text to US-ASCII.

File

./transliteration.inc, line 178
Transliteration processing functions.

Code

function _transliteration_replace($ord, $unknown = '?', $langcode = NULL) {
  static $map = array();
  if (!isset($langcode)) {
    global $language;
    $langcode = $language->language;
  }
  $bank = $ord >> 8;
  if (!isset($map[$bank][$langcode])) {
    $file = drupal_get_path('module', 'transliteration') . '/data/' . sprintf('x%02x', $bank) . '.php';
    if (file_exists($file)) {
      include $file;

      // $base and/or $variant can be exists by included file. @codingStandardsIgnoreLine
      if ($langcode != 'en' && isset($variant[$langcode])) {

        // Merge in language specific mappings. @codingStandardsIgnoreLine
        $map[$bank][$langcode] = $variant[$langcode] + $base;
      }
      else {

        // @codingStandardsIgnoreLine
        $map[$bank][$langcode] = $base;
      }
    }
    else {
      $map[$bank][$langcode] = array();
    }
  }
  $ord = $ord & 255;
  return isset($map[$bank][$langcode][$ord]) ? $map[$bank][$langcode][$ord] : $unknown;
}