function PhpTransliteration::removeDiacritics
Same name in other branches
- 9 core/lib/Drupal/Component/Transliteration/PhpTransliteration.php \Drupal\Component\Transliteration\PhpTransliteration::removeDiacritics()
- 8.9.x core/lib/Drupal/Component/Transliteration/PhpTransliteration.php \Drupal\Component\Transliteration\PhpTransliteration::removeDiacritics()
- 10 core/lib/Drupal/Component/Transliteration/PhpTransliteration.php \Drupal\Component\Transliteration\PhpTransliteration::removeDiacritics()
Overrides TransliterationInterface::removeDiacritics
File
-
core/
lib/ Drupal/ Component/ Transliteration/ PhpTransliteration.php, line 95
Class
- PhpTransliteration
- Implements transliteration without using the PECL extensions.
Namespace
Drupal\Component\TransliterationCode
public function removeDiacritics($string) {
$result = '';
foreach (preg_split('//u', $string, 0, PREG_SPLIT_NO_EMPTY) as $character) {
$code = self::ordUTF8($character);
// These two Unicode ranges include the accented US-ASCII letters, with a
// few characters that aren't accented letters mixed in. So define the
// ranges and the excluded characters.
$range1 = $code > 0xbf && $code < 0x17f;
$exclusions_range1 = [
0xd0,
0xd7,
0xf0,
0xf7,
0x138,
0x14a,
0x14b,
];
$range2 = $code > 0x1cc && $code < 0x250;
$exclusions_range2 = [
0x1dd,
0x1f7,
0x21c,
0x21d,
0x220,
0x221,
0x241,
0x242,
0x245,
];
$replacement = $character;
if ($range1 && !in_array($code, $exclusions_range1) || $range2 && !in_array($code, $exclusions_range2)) {
$to_add = $this->lookupReplacement($code, 'xyz');
if (strlen($to_add) === 1) {
$replacement = $to_add;
}
elseif (isset($this->fixTransliterateForRemoveDiacritics[$to_add])) {
$replacement = $this->fixTransliterateForRemoveDiacritics[$to_add];
}
}
$result .= $replacement;
}
return $result;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.