Last active
October 2, 2018 07:58
-
-
Save stefanbc/36ef3294a8f316f9b588 to your computer and use it in GitHub Desktop.
Convert all diacritics in a string to a string without diacritics
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function replaceDiacritics($str) { | |
return preg_replace( | |
array( | |
/* Lowercase */ | |
'/[\x{0105}\x{00E0}\x{00E1}\x{00E2}\x{00E3}\x{00E4}\x{00E5}]/u', | |
'/[\x{00E7}\x{010D}\x{0107}]/u', | |
'/[\x{010F}]/u', | |
'/[\x{00E8}\x{00E9}\x{00EA}\x{00EB}\x{011B}\x{0119}]/u', | |
'/[\x{00EC}\x{00ED}\x{00EE}\x{00EF}]/u', | |
'/[\x{0142}\x{013E}\x{013A}]/u', | |
'/[\x{00F1}\x{0148}]/u', | |
'/[\x{00F2}\x{00F3}\x{00F4}\x{00F5}\x{00F6}\x{00F8}]/u', | |
'/[\x{0159}\x{0155}]/u', | |
'/[\x{015B}\x{0161}]/u', | |
'/[\x{00DF}]/u', | |
'/[\x{0165}]/u', | |
'/[\x{00F9}\x{00FA}\x{00FB}\x{00FC}\x{016F}]/u', | |
'/[\x{00FD}\x{00FF}]/u', | |
'/[\x{017C}\x{017A}\x{017E}]/u', | |
'/[\x{00E6}]/u', | |
'/[\x{0153}]/u', | |
/* Uppercase */ | |
'/[\x{0104}\x{00C0}\x{00C1}\x{00C2}\x{00C3}\x{00C4}\x{00C5}]/u', | |
'/[\x{00C7}\x{010C}\x{0106}]/u', | |
'/[\x{010E}]/u', | |
'/[\x{00C8}\x{00C9}\x{00CA}\x{00CB}\x{011A}\x{0118}]/u', | |
'/[\x{0141}\x{013D}\x{0139}]/u', | |
'/[\x{00D1}\x{0147}]/u', | |
'/[\x{00D3}]/u', | |
'/[\x{0158}\x{0154}]/u', | |
'/[\x{015A}\x{0160}]/u', | |
'/[\x{0164}]/u', | |
'/[\x{00D9}\x{00DA}\x{00DB}\x{00DC}\x{016E}]/u', | |
'/[\x{017B}\x{0179}\x{017D}]/u', | |
'/[\x{00C6}]/u', | |
'/[\x{0152}]/u', | |
), | |
array( | |
'a', 'c', 'd', 'e', 'i', 'l', 'n', 'o', 'r', 's', 'ss', 't', 'u', 'y', 'z', 'ae', 'oe', | |
'A', 'C', 'D', 'E', 'L', 'N', 'O', 'R', 'S', 'T', 'U', 'Z', 'AE', 'OE' | |
), | |
$str); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment