1 transliteration.inc _transliteration_replace($ord, $unknown = '?', $langcode = NULL)

Replaces a Unicode character using the transliteration database.

Parameters

$ord: An ordinal Unicode character code.

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

$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

ASCII replacement character.:

File

core/includes/transliteration.inc, line 177
Transliteration processing functions.

Code

function _transliteration_replace($ord, $unknown = '?', $langcode = NULL) {
  static $map = array();
  static $language_overrides = array();

  if (!isset($langcode)) {
    global $language;
    $langcode = $language->langcode;
  }

  // See if there is a language-specific override for this character.
  if (!isset($language_overrides[$langcode])) {
    $file = BACKDROP_ROOT . '/core/includes/transliteration/' . preg_replace('/[^a-zA-Z\-]/', '', $langcode) . '.php';
    if (file_exists($file)) {
      include $file;
      if (!isset($overrides[$langcode]) || !is_array($overrides[$langcode])) {
        $overrides[$langcode] = array();
      }
      $language_overrides[$langcode] = $overrides[$langcode];
    }
  }
  if (isset($language_overrides[$langcode][$ord])) {
    return $language_overrides[$langcode][$ord];
  }

  $bank = $ord >> 8;

  if (!isset($map[$bank][$langcode])) {
    $base = array(); // Populated from the include.
    $file = BACKDROP_ROOT . '/core/includes/transliteration/' . sprintf('x%02x', $bank) . '.php';
    if (file_exists($file)) {
      include $file;
      $map[$bank][$langcode] = $base;
    }
    else {
      $map[$bank][$langcode] = array();
    }
  }

  $ord = $ord & 255;

  return isset($map[$bank][$langcode][$ord]) ? $map[$bank][$langcode][$ord] : $unknown;
}