remove_accents() WordPress Function

The remove_accents() function is used to remove any accents from a string. This is useful for strings that are going to be used in URLs or in other situations where special characters can cause problems.

remove_accents( string $string, string $locale = '' ) #

Converts all accent characters to ASCII characters.


Description

If there are no accent characters, then the string given is just returned.

Accent characters converted:

Currency signs:

CodeGlyphReplacementDescription
U+00A3£(empty)British Pound sign
U+20ACEEuro sign

Decompositions for Latin-1 Supplement:

CodeGlyphReplacementDescription
U+00AAªaFeminine ordinal indicator
U+00BAºoMasculine ordinal indicator
U+00C0ÀALatin capital letter A with grave
U+00C1ÁALatin capital letter A with acute
U+00C2ÂALatin capital letter A with circumflex
U+00C3ÃALatin capital letter A with tilde
U+00C4ÄALatin capital letter A with diaeresis
U+00C5ÅALatin capital letter A with ring above
U+00C6ÆAELatin capital letter AE
U+00C7ÇCLatin capital letter C with cedilla
U+00C8ÈELatin capital letter E with grave
U+00C9ÉELatin capital letter E with acute
U+00CAÊELatin capital letter E with circumflex
U+00CBËELatin capital letter E with diaeresis
U+00CCÌILatin capital letter I with grave
U+00CDÍILatin capital letter I with acute
U+00CEÎILatin capital letter I with circumflex
U+00CFÏILatin capital letter I with diaeresis
U+00D0ÐDLatin capital letter Eth
U+00D1ÑNLatin capital letter N with tilde
U+00D2ÒOLatin capital letter O with grave
U+00D3ÓOLatin capital letter O with acute
U+00D4ÔOLatin capital letter O with circumflex
U+00D5ÕOLatin capital letter O with tilde
U+00D6ÖOLatin capital letter O with diaeresis
U+00D8ØOLatin capital letter O with stroke
U+00D9ÙULatin capital letter U with grave
U+00DAÚULatin capital letter U with acute
U+00DBÛULatin capital letter U with circumflex
U+00DCÜULatin capital letter U with diaeresis
U+00DDÝYLatin capital letter Y with acute
U+00DEÞTHLatin capital letter Thorn
U+00DFßsLatin small letter sharp s
U+00E0àaLatin small letter a with grave
U+00E1áaLatin small letter a with acute
U+00E2âaLatin small letter a with circumflex
U+00E3ãaLatin small letter a with tilde
U+00E4äaLatin small letter a with diaeresis
U+00E5åaLatin small letter a with ring above
U+00E6æaeLatin small letter ae
U+00E7çcLatin small letter c with cedilla
U+00E8èeLatin small letter e with grave
U+00E9éeLatin small letter e with acute
U+00EAêeLatin small letter e with circumflex
U+00EBëeLatin small letter e with diaeresis
U+00ECìiLatin small letter i with grave
U+00EDíiLatin small letter i with acute
U+00EEîiLatin small letter i with circumflex
U+00EFïiLatin small letter i with diaeresis
U+00F0ðdLatin small letter Eth
U+00F1ñnLatin small letter n with tilde
U+00F2òoLatin small letter o with grave
U+00F3óoLatin small letter o with acute
U+00F4ôoLatin small letter o with circumflex
U+00F5õoLatin small letter o with tilde
U+00F6öoLatin small letter o with diaeresis
U+00F8øoLatin small letter o with stroke
U+00F9ùuLatin small letter u with grave
U+00FAúuLatin small letter u with acute
U+00FBûuLatin small letter u with circumflex
U+00FCüuLatin small letter u with diaeresis
U+00FDýyLatin small letter y with acute
U+00FEþthLatin small letter Thorn
U+00FFÿyLatin small letter y with diaeresis

Decompositions for Latin Extended-A:

CodeGlyphReplacementDescription
U+0100ĀALatin capital letter A with macron
U+0101āaLatin small letter a with macron
U+0102ĂALatin capital letter A with breve
U+0103ăaLatin small letter a with breve
U+0104ĄALatin capital letter A with ogonek
U+0105ąaLatin small letter a with ogonek
U+01006ĆCLatin capital letter C with acute
U+0107ćcLatin small letter c with acute
U+0108ĈCLatin capital letter C with circumflex
U+0109ĉcLatin small letter c with circumflex
U+010AĊCLatin capital letter C with dot above
U+010BċcLatin small letter c with dot above
U+010CČCLatin capital letter C with caron
U+010DčcLatin small letter c with caron
U+010EĎDLatin capital letter D with caron
U+010FďdLatin small letter d with caron
U+0110ĐDLatin capital letter D with stroke
U+0111đdLatin small letter d with stroke
U+0112ĒELatin capital letter E with macron
U+0113ēeLatin small letter e with macron
U+0114ĔELatin capital letter E with breve
U+0115ĕeLatin small letter e with breve
U+0116ĖELatin capital letter E with dot above
U+0117ėeLatin small letter e with dot above
U+0118ĘELatin capital letter E with ogonek
U+0119ęeLatin small letter e with ogonek
U+011AĚELatin capital letter E with caron
U+011BěeLatin small letter e with caron
U+011CĜGLatin capital letter G with circumflex
U+011DĝgLatin small letter g with circumflex
U+011EĞGLatin capital letter G with breve
U+011FğgLatin small letter g with breve
U+0120ĠGLatin capital letter G with dot above
U+0121ġgLatin small letter g with dot above
U+0122ĢGLatin capital letter G with cedilla
U+0123ģgLatin small letter g with cedilla
U+0124ĤHLatin capital letter H with circumflex
U+0125ĥhLatin small letter h with circumflex
U+0126ĦHLatin capital letter H with stroke
U+0127ħhLatin small letter h with stroke
U+0128ĨILatin capital letter I with tilde
U+0129ĩiLatin small letter i with tilde
U+012AĪILatin capital letter I with macron
U+012BīiLatin small letter i with macron
U+012CĬILatin capital letter I with breve
U+012DĭiLatin small letter i with breve
U+012EĮILatin capital letter I with ogonek
U+012FįiLatin small letter i with ogonek
U+0130İILatin capital letter I with dot above
U+0131ıiLatin small letter dotless i
U+0132IJIJLatin capital ligature IJ
U+0133ijijLatin small ligature ij
U+0134ĴJLatin capital letter J with circumflex
U+0135ĵjLatin small letter j with circumflex
U+0136ĶKLatin capital letter K with cedilla
U+0137ķkLatin small letter k with cedilla
U+0138ĸkLatin small letter Kra
U+0139ĹLLatin capital letter L with acute
U+013AĺlLatin small letter l with acute
U+013BĻLLatin capital letter L with cedilla
U+013CļlLatin small letter l with cedilla
U+013DĽLLatin capital letter L with caron
U+013EľlLatin small letter l with caron
U+013FĿLLatin capital letter L with middle dot
U+0140ŀlLatin small letter l with middle dot
U+0141ŁLLatin capital letter L with stroke
U+0142łlLatin small letter l with stroke
U+0143ŃNLatin capital letter N with acute
U+0144ńnLatin small letter N with acute
U+0145ŅNLatin capital letter N with cedilla
U+0146ņnLatin small letter n with cedilla
U+0147ŇNLatin capital letter N with caron
U+0148ňnLatin small letter n with caron
U+0149ʼnnLatin small letter n preceded by apostrophe
U+014AŊNLatin capital letter Eng
U+014BŋnLatin small letter Eng
U+014CŌOLatin capital letter O with macron
U+014DōoLatin small letter o with macron
U+014EŎOLatin capital letter O with breve
U+014FŏoLatin small letter o with breve
U+0150ŐOLatin capital letter O with double acute
U+0151őoLatin small letter o with double acute
U+0152ŒOELatin capital ligature OE
U+0153œoeLatin small ligature oe
U+0154ŔRLatin capital letter R with acute
U+0155ŕrLatin small letter r with acute
U+0156ŖRLatin capital letter R with cedilla
U+0157ŗrLatin small letter r with cedilla
U+0158ŘRLatin capital letter R with caron
U+0159řrLatin small letter r with caron
U+015AŚSLatin capital letter S with acute
U+015BśsLatin small letter s with acute
U+015CŜSLatin capital letter S with circumflex
U+015DŝsLatin small letter s with circumflex
U+015EŞSLatin capital letter S with cedilla
U+015FşsLatin small letter s with cedilla
U+0160ŠSLatin capital letter S with caron
U+0161šsLatin small letter s with caron
U+0162ŢTLatin capital letter T with cedilla
U+0163ţtLatin small letter t with cedilla
U+0164ŤTLatin capital letter T with caron
U+0165ťtLatin small letter t with caron
U+0166ŦTLatin capital letter T with stroke
U+0167ŧtLatin small letter t with stroke
U+0168ŨULatin capital letter U with tilde
U+0169ũuLatin small letter u with tilde
U+016AŪULatin capital letter U with macron
U+016BūuLatin small letter u with macron
U+016CŬULatin capital letter U with breve
U+016DŭuLatin small letter u with breve
U+016EŮULatin capital letter U with ring above
U+016FůuLatin small letter u with ring above
U+0170ŰULatin capital letter U with double acute
U+0171űuLatin small letter u with double acute
U+0172ŲULatin capital letter U with ogonek
U+0173ųuLatin small letter u with ogonek
U+0174ŴWLatin capital letter W with circumflex
U+0175ŵwLatin small letter w with circumflex
U+0176ŶYLatin capital letter Y with circumflex
U+0177ŷyLatin small letter y with circumflex
U+0178ŸYLatin capital letter Y with diaeresis
U+0179ŹZLatin capital letter Z with acute
U+017AźzLatin small letter z with acute
U+017BŻZLatin capital letter Z with dot above
U+017CżzLatin small letter z with dot above
U+017DŽZLatin capital letter Z with caron
U+017EžzLatin small letter z with caron
U+017FſsLatin small letter long s
U+01A0ƠOLatin capital letter O with horn
U+01A1ơoLatin small letter o with horn
U+01AFƯULatin capital letter U with horn
U+01B0ưuLatin small letter u with horn
U+01CDǍALatin capital letter A with caron
U+01CEǎaLatin small letter a with caron
U+01CFǏILatin capital letter I with caron
U+01D0ǐiLatin small letter i with caron
U+01D1ǑOLatin capital letter O with caron
U+01D2ǒoLatin small letter o with caron
U+01D3ǓULatin capital letter U with caron
U+01D4ǔuLatin small letter u with caron
U+01D5ǕULatin capital letter U with diaeresis and macron
U+01D6ǖuLatin small letter u with diaeresis and macron
U+01D7ǗULatin capital letter U with diaeresis and acute
U+01D8ǘuLatin small letter u with diaeresis and acute
U+01D9ǙULatin capital letter U with diaeresis and caron
U+01DAǚuLatin small letter u with diaeresis and caron
U+01DBǛULatin capital letter U with diaeresis and grave
U+01DCǜuLatin small letter u with diaeresis and grave

Decompositions for Latin Extended-B:

CodeGlyphReplacementDescription
U+0218ȘSLatin capital letter S with comma below
U+0219șsLatin small letter s with comma below
U+021AȚTLatin capital letter T with comma below
U+021BțtLatin small letter t with comma below

Vowels with diacritic (Chinese, Hanyu Pinyin):

CodeGlyphReplacementDescription
U+0251ɑaLatin small letter alpha
U+1EA0ALatin capital letter A with dot below
U+1EA1aLatin small letter a with dot below
U+1EA2ALatin capital letter A with hook above
U+1EA3aLatin small letter a with hook above
U+1EA4ALatin capital letter A with circumflex and acute
U+1EA5aLatin small letter a with circumflex and acute
U+1EA6ALatin capital letter A with circumflex and grave
U+1EA7aLatin small letter a with circumflex and grave
U+1EA8ALatin capital letter A with circumflex and hook above
U+1EA9aLatin small letter a with circumflex and hook above
U+1EAAALatin capital letter A with circumflex and tilde
U+1EABaLatin small letter a with circumflex and tilde
U+1EA6ALatin capital letter A with circumflex and dot below
U+1EADaLatin small letter a with circumflex and dot below
U+1EAEALatin capital letter A with breve and acute
U+1EAFaLatin small letter a with breve and acute
U+1EB0ALatin capital letter A with breve and grave
U+1EB1aLatin small letter a with breve and grave
U+1EB2ALatin capital letter A with breve and hook above
U+1EB3aLatin small letter a with breve and hook above
U+1EB4ALatin capital letter A with breve and tilde
U+1EB5aLatin small letter a with breve and tilde
U+1EB6ALatin capital letter A with breve and dot below
U+1EB7aLatin small letter a with breve and dot below
U+1EB8ELatin capital letter E with dot below
U+1EB9eLatin small letter e with dot below
U+1EBAELatin capital letter E with hook above
U+1EBBeLatin small letter e with hook above
U+1EBCELatin capital letter E with tilde
U+1EBDeLatin small letter e with tilde
U+1EBEELatin capital letter E with circumflex and acute
U+1EBFếeLatin small letter e with circumflex and acute
U+1EC0ELatin capital letter E with circumflex and grave
U+1EC1eLatin small letter e with circumflex and grave
U+1EC2ELatin capital letter E with circumflex and hook above
U+1EC3eLatin small letter e with circumflex and hook above
U+1EC4ELatin capital letter E with circumflex and tilde
U+1EC5eLatin small letter e with circumflex and tilde
U+1EC6ELatin capital letter E with circumflex and dot below
U+1EC7eLatin small letter e with circumflex and dot below
U+1EC8ILatin capital letter I with hook above
U+1EC9iLatin small letter i with hook above
U+1ECAILatin capital letter I with dot below
U+1ECBiLatin small letter i with dot below
U+1ECCOLatin capital letter O with dot below
U+1ECDoLatin small letter o with dot below
U+1ECEOLatin capital letter O with hook above
U+1ECFoLatin small letter o with hook above
U+1ED0OLatin capital letter O with circumflex and acute
U+1ED1oLatin small letter o with circumflex and acute
U+1ED2OLatin capital letter O with circumflex and grave
U+1ED3oLatin small letter o with circumflex and grave
U+1ED4OLatin capital letter O with circumflex and hook above
U+1ED5oLatin small letter o with circumflex and hook above
U+1ED6OLatin capital letter O with circumflex and tilde
U+1ED7oLatin small letter o with circumflex and tilde
U+1ED8OLatin capital letter O with circumflex and dot below
U+1ED9oLatin small letter o with circumflex and dot below
U+1EDAOLatin capital letter O with horn and acute
U+1EDBoLatin small letter o with horn and acute
U+1EDCOLatin capital letter O with horn and grave
U+1EDDoLatin small letter o with horn and grave
U+1EDEOLatin capital letter O with horn and hook above
U+1EDFoLatin small letter o with horn and hook above
U+1EE0OLatin capital letter O with horn and tilde
U+1EE1oLatin small letter o with horn and tilde
U+1EE2OLatin capital letter O with horn and dot below
U+1EE3oLatin small letter o with horn and dot below
U+1EE4ULatin capital letter U with dot below
U+1EE5uLatin small letter u with dot below
U+1EE6ULatin capital letter U with hook above
U+1EE7uLatin small letter u with hook above
U+1EE8ULatin capital letter U with horn and acute
U+1EE9uLatin small letter u with horn and acute
U+1EEAULatin capital letter U with horn and grave
U+1EEBuLatin small letter u with horn and grave
U+1EECULatin capital letter U with horn and hook above
U+1EEDuLatin small letter u with horn and hook above
U+1EEEULatin capital letter U with horn and tilde
U+1EEFuLatin small letter u with horn and tilde
U+1EF0ULatin capital letter U with horn and dot below
U+1EF1uLatin small letter u with horn and dot below
U+1EF2YLatin capital letter Y with grave
U+1EF3yLatin small letter y with grave
U+1EF4YLatin capital letter Y with dot below
U+1EF5yLatin small letter y with dot below
U+1EF6YLatin capital letter Y with hook above
U+1EF7yLatin small letter y with hook above
U+1EF8YLatin capital letter Y with tilde
U+1EF9yLatin small letter y with tilde

German (de_DE), German formal (de_DE_formal), German (Switzerland) formal (de_CH), German (Switzerland) informal (de_CH_informal), and German (Austria) (de_AT) locales:

CodeGlyphReplacementDescription
U+00C4ÄAeLatin capital letter A with diaeresis
U+00E4äaeLatin small letter a with diaeresis
U+00D6ÖOeLatin capital letter O with diaeresis
U+00F6öoeLatin small letter o with diaeresis
U+00DCÜUeLatin capital letter U with diaeresis
U+00FCüueLatin small letter u with diaeresis
U+00DFßssLatin small letter sharp s

Danish (da_DK) locale:

CodeGlyphReplacementDescription
U+00C6ÆAeLatin capital letter AE
U+00E6æaeLatin small letter ae
U+00D8ØOeLatin capital letter O with stroke
U+00F8øoeLatin small letter o with stroke
U+00C5ÅAaLatin capital letter A with ring above
U+00E5åaaLatin small letter a with ring above

Catalan (ca) locale:

CodeGlyphReplacementDescription
U+00B7l·lllFlown dot (between two Ls)

Serbian (sr_RS) and Bosnian (bs_BA) locales:

CodeGlyphReplacementDescription
U+0110ĐDJLatin capital letter D with stroke
U+0111đdjLatin small letter d with stroke

Top ↑

Parameters

$string

(string)(Required)Text that might have accent characters.

$locale

(string)(Optional) The locale to use for accent removal. Some character replacements depend on the locale being used (e.g. 'de_DE'). Defaults to the current locale.

Default value: ''


Top ↑

Return

(string) Filtered string with replaced "nice" characters.


Top ↑

Source

File: wp-includes/formatting.php

function remove_accents( $string, $locale = '' ) {
	if ( ! preg_match( '/[\x80-\xff]/', $string ) ) {
		return $string;
	}

	if ( seems_utf8( $string ) ) {
		$chars = array(
			// Decompositions for Latin-1 Supplement.
			'ª' => 'a',
			'º' => 'o',
			'À' => 'A',
			'Á' => 'A',
			'Â' => 'A',
			'Ã' => 'A',
			'Ä' => 'A',
			'Å' => 'A',
			'Æ' => 'AE',
			'Ç' => 'C',
			'È' => 'E',
			'É' => 'E',
			'Ê' => 'E',
			'Ë' => 'E',
			'Ì' => 'I',
			'Í' => 'I',
			'Î' => 'I',
			'Ï' => 'I',
			'Ð' => 'D',
			'Ñ' => 'N',
			'Ò' => 'O',
			'Ó' => 'O',
			'Ô' => 'O',
			'Õ' => 'O',
			'Ö' => 'O',
			'Ù' => 'U',
			'Ú' => 'U',
			'Û' => 'U',
			'Ü' => 'U',
			'Ý' => 'Y',
			'Þ' => 'TH',
			'ß' => 's',
			'à' => 'a',
			'á' => 'a',
			'â' => 'a',
			'ã' => 'a',
			'ä' => 'a',
			'å' => 'a',
			'æ' => 'ae',
			'ç' => 'c',
			'è' => 'e',
			'é' => 'e',
			'ê' => 'e',
			'ë' => 'e',
			'ì' => 'i',
			'í' => 'i',
			'î' => 'i',
			'ï' => 'i',
			'ð' => 'd',
			'ñ' => 'n',
			'ò' => 'o',
			'ó' => 'o',
			'ô' => 'o',
			'õ' => 'o',
			'ö' => 'o',
			'ø' => 'o',
			'ù' => 'u',
			'ú' => 'u',
			'û' => 'u',
			'ü' => 'u',
			'ý' => 'y',
			'þ' => 'th',
			'ÿ' => 'y',
			'Ø' => 'O',
			// Decompositions for Latin Extended-A.
			'Ā' => 'A',
			'ā' => 'a',
			'Ă' => 'A',
			'ă' => 'a',
			'Ą' => 'A',
			'ą' => 'a',
			'Ć' => 'C',
			'ć' => 'c',
			'Ĉ' => 'C',
			'ĉ' => 'c',
			'Ċ' => 'C',
			'ċ' => 'c',
			'Č' => 'C',
			'č' => 'c',
			'Ď' => 'D',
			'ď' => 'd',
			'Đ' => 'D',
			'đ' => 'd',
			'Ē' => 'E',
			'ē' => 'e',
			'Ĕ' => 'E',
			'ĕ' => 'e',
			'Ė' => 'E',
			'ė' => 'e',
			'Ę' => 'E',
			'ę' => 'e',
			'Ě' => 'E',
			'ě' => 'e',
			'Ĝ' => 'G',
			'ĝ' => 'g',
			'Ğ' => 'G',
			'ğ' => 'g',
			'Ġ' => 'G',
			'ġ' => 'g',
			'Ģ' => 'G',
			'ģ' => 'g',
			'Ĥ' => 'H',
			'ĥ' => 'h',
			'Ħ' => 'H',
			'ħ' => 'h',
			'Ĩ' => 'I',
			'ĩ' => 'i',
			'Ī' => 'I',
			'ī' => 'i',
			'Ĭ' => 'I',
			'ĭ' => 'i',
			'Į' => 'I',
			'į' => 'i',
			'İ' => 'I',
			'ı' => 'i',
			'IJ' => 'IJ',
			'ij' => 'ij',
			'Ĵ' => 'J',
			'ĵ' => 'j',
			'Ķ' => 'K',
			'ķ' => 'k',
			'ĸ' => 'k',
			'Ĺ' => 'L',
			'ĺ' => 'l',
			'Ļ' => 'L',
			'ļ' => 'l',
			'Ľ' => 'L',
			'ľ' => 'l',
			'Ŀ' => 'L',
			'ŀ' => 'l',
			'Ł' => 'L',
			'ł' => 'l',
			'Ń' => 'N',
			'ń' => 'n',
			'Ņ' => 'N',
			'ņ' => 'n',
			'Ň' => 'N',
			'ň' => 'n',
			'ʼn' => 'n',
			'Ŋ' => 'N',
			'ŋ' => 'n',
			'Ō' => 'O',
			'ō' => 'o',
			'Ŏ' => 'O',
			'ŏ' => 'o',
			'Ő' => 'O',
			'ő' => 'o',
			'Œ' => 'OE',
			'œ' => 'oe',
			'Ŕ' => 'R',
			'ŕ' => 'r',
			'Ŗ' => 'R',
			'ŗ' => 'r',
			'Ř' => 'R',
			'ř' => 'r',
			'Ś' => 'S',
			'ś' => 's',
			'Ŝ' => 'S',
			'ŝ' => 's',
			'Ş' => 'S',
			'ş' => 's',
			'Š' => 'S',
			'š' => 's',
			'Ţ' => 'T',
			'ţ' => 't',
			'Ť' => 'T',
			'ť' => 't',
			'Ŧ' => 'T',
			'ŧ' => 't',
			'Ũ' => 'U',
			'ũ' => 'u',
			'Ū' => 'U',
			'ū' => 'u',
			'Ŭ' => 'U',
			'ŭ' => 'u',
			'Ů' => 'U',
			'ů' => 'u',
			'Ű' => 'U',
			'ű' => 'u',
			'Ų' => 'U',
			'ų' => 'u',
			'Ŵ' => 'W',
			'ŵ' => 'w',
			'Ŷ' => 'Y',
			'ŷ' => 'y',
			'Ÿ' => 'Y',
			'Ź' => 'Z',
			'ź' => 'z',
			'Ż' => 'Z',
			'ż' => 'z',
			'Ž' => 'Z',
			'ž' => 'z',
			'ſ' => 's',
			// Decompositions for Latin Extended-B.
			'Ș' => 'S',
			'ș' => 's',
			'Ț' => 'T',
			'ț' => 't',
			// Euro sign.
			'€' => 'E',
			// GBP (Pound) sign.
			'£' => '',
			// Vowels with diacritic (Vietnamese).
			// Unmarked.
			'Ơ' => 'O',
			'ơ' => 'o',
			'Ư' => 'U',
			'ư' => 'u',
			// Grave accent.
			'Ầ' => 'A',
			'ầ' => 'a',
			'Ằ' => 'A',
			'ằ' => 'a',
			'Ề' => 'E',
			'ề' => 'e',
			'Ồ' => 'O',
			'ồ' => 'o',
			'Ờ' => 'O',
			'ờ' => 'o',
			'Ừ' => 'U',
			'ừ' => 'u',
			'Ỳ' => 'Y',
			'ỳ' => 'y',
			// Hook.
			'Ả' => 'A',
			'ả' => 'a',
			'Ẩ' => 'A',
			'ẩ' => 'a',
			'Ẳ' => 'A',
			'ẳ' => 'a',
			'Ẻ' => 'E',
			'ẻ' => 'e',
			'Ể' => 'E',
			'ể' => 'e',
			'Ỉ' => 'I',
			'ỉ' => 'i',
			'Ỏ' => 'O',
			'ỏ' => 'o',
			'Ổ' => 'O',
			'ổ' => 'o',
			'Ở' => 'O',
			'ở' => 'o',
			'Ủ' => 'U',
			'ủ' => 'u',
			'Ử' => 'U',
			'ử' => 'u',
			'Ỷ' => 'Y',
			'ỷ' => 'y',
			// Tilde.
			'Ẫ' => 'A',
			'ẫ' => 'a',
			'Ẵ' => 'A',
			'ẵ' => 'a',
			'Ẽ' => 'E',
			'ẽ' => 'e',
			'Ễ' => 'E',
			'ễ' => 'e',
			'Ỗ' => 'O',
			'ỗ' => 'o',
			'Ỡ' => 'O',
			'ỡ' => 'o',
			'Ữ' => 'U',
			'ữ' => 'u',
			'Ỹ' => 'Y',
			'ỹ' => 'y',
			// Acute accent.
			'Ấ' => 'A',
			'ấ' => 'a',
			'Ắ' => 'A',
			'ắ' => 'a',
			'Ế' => 'E',
			'ế' => 'e',
			'Ố' => 'O',
			'ố' => 'o',
			'Ớ' => 'O',
			'ớ' => 'o',
			'Ứ' => 'U',
			'ứ' => 'u',
			// Dot below.
			'Ạ' => 'A',
			'ạ' => 'a',
			'Ậ' => 'A',
			'ậ' => 'a',
			'Ặ' => 'A',
			'ặ' => 'a',
			'Ẹ' => 'E',
			'ẹ' => 'e',
			'Ệ' => 'E',
			'ệ' => 'e',
			'Ị' => 'I',
			'ị' => 'i',
			'Ọ' => 'O',
			'ọ' => 'o',
			'Ộ' => 'O',
			'ộ' => 'o',
			'Ợ' => 'O',
			'ợ' => 'o',
			'Ụ' => 'U',
			'ụ' => 'u',
			'Ự' => 'U',
			'ự' => 'u',
			'Ỵ' => 'Y',
			'ỵ' => 'y',
			// Vowels with diacritic (Chinese, Hanyu Pinyin).
			'ɑ' => 'a',
			// Macron.
			'Ǖ' => 'U',
			'ǖ' => 'u',
			// Acute accent.
			'Ǘ' => 'U',
			'ǘ' => 'u',
			// Caron.
			'Ǎ' => 'A',
			'ǎ' => 'a',
			'Ǐ' => 'I',
			'ǐ' => 'i',
			'Ǒ' => 'O',
			'ǒ' => 'o',
			'Ǔ' => 'U',
			'ǔ' => 'u',
			'Ǚ' => 'U',
			'ǚ' => 'u',
			// Grave accent.
			'Ǜ' => 'U',
			'ǜ' => 'u',
		);

		// Used for locale-specific rules.
		if ( empty( $locale ) ) {
			$locale = get_locale();
		}

		/*
		 * German has various locales (de_DE, de_CH, de_AT, ...) with formal and informal variants.
		 * There is no 3-letter locale like 'def', so checking for 'de' instead of 'de_' is safe,
		 * since 'de' itself would be a valid locale too.
		 */
		if ( str_starts_with( $locale, 'de' ) ) {
			$chars['Ä'] = 'Ae';
			$chars['ä'] = 'ae';
			$chars['Ö'] = 'Oe';
			$chars['ö'] = 'oe';
			$chars['Ü'] = 'Ue';
			$chars['ü'] = 'ue';
			$chars['ß'] = 'ss';
		} elseif ( 'da_DK' === $locale ) {
			$chars['Æ'] = 'Ae';
			$chars['æ'] = 'ae';
			$chars['Ø'] = 'Oe';
			$chars['ø'] = 'oe';
			$chars['Å'] = 'Aa';
			$chars['å'] = 'aa';
		} elseif ( 'ca' === $locale ) {
			$chars['l·l'] = 'll';
		} elseif ( 'sr_RS' === $locale || 'bs_BA' === $locale ) {
			$chars['Đ'] = 'DJ';
			$chars['đ'] = 'dj';
		}

		$string = strtr( $string, $chars );
	} else {
		$chars = array();
		// Assume ISO-8859-1 if not UTF-8.
		$chars['in'] = "\x80\x83\x8a\x8e\x9a\x9e"
			. "\x9f\xa2\xa5\xb5\xc0\xc1\xc2"
			. "\xc3\xc4\xc5\xc7\xc8\xc9\xca"
			. "\xcb\xcc\xcd\xce\xcf\xd1\xd2"
			. "\xd3\xd4\xd5\xd6\xd8\xd9\xda"
			. "\xdb\xdc\xdd\xe0\xe1\xe2\xe3"
			. "\xe4\xe5\xe7\xe8\xe9\xea\xeb"
			. "\xec\xed\xee\xef\xf1\xf2\xf3"
			. "\xf4\xf5\xf6\xf8\xf9\xfa\xfb"
			. "\xfc\xfd\xff";

		$chars['out'] = 'EfSZszYcYuAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy';

		$string              = strtr( $string, $chars['in'], $chars['out'] );
		$double_chars        = array();
		$double_chars['in']  = array( "\x8c", "\x9c", "\xc6", "\xd0", "\xde", "\xdf", "\xe6", "\xf0", "\xfe" );
		$double_chars['out'] = array( 'OE', 'oe', 'AE', 'DH', 'TH', 'ss', 'ae', 'dh', 'th' );
		$string              = str_replace( $double_chars['in'], $double_chars['out'], $string );
	}

	return $string;
}


Top ↑

Changelog

Changelog
VersionDescription
6.0.0Added the $locale parameter.
5.7.0Added locale support for de_AT.
4.8.0Added locale support for bs_BA.
4.7.0Added locale support for sr_RS.
4.6.0Added locale support for de_CH, de_CH_informal, and ca.
1.2.1Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by the Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More