public PhpTransliteration::removeDiacritics($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.
Overrides TransliterationInterface::removeDiacritics
File
- core/lib/Drupal/Component/Transliteration/PhpTransliteration.php, line 76
Class
- PhpTransliteration
- Implements transliteration without using the PECL extensions.
Namespace
Drupal\Component\Transliteration
Code
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 > 0x00bf && $code < 0x017f; $exclusions_range1 = array(0x00d0, 0x00d7, 0x00f0, 0x00f7, 0x0138, 0x014a, 0x014b); $range2 = $code > 0x01cc && $code < 0x0250; $exclusions_range2 = array(0x01DD, 0x01f7, 0x021c, 0x021d, 0x0220, 0x0221, 0x0241, 0x0242, 0x0245); $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; } } $result .= $replacement; } return $result; }
Please login to continue.