In this Article I’ll explain you how you can replace French letters with their English letters. In some cases you may need to change French special characters with their English letters for your target audience. Like
- Š => S
- š => s
- Ð => Dj
- Ž => Z
You can replace these letters with too many methods. But here I’ll highlight 2 methods:
- strtr — Translate characters or replace substrings
- str_replace — Replace all occurrences of the search string with the replacement string
Replace French letters with ‘strtr’ function
Translating the letters:
$normalizeChars = array(
'Š'=>'S', 'š'=>'s', 'Ð'=>'Dj','Ž'=>'Z', 'ž'=>'z', 'À'=>'A'
$string = strtr($string, $normalizeChars);
In above example strtr function will search the key (array-key of second parameter) and will replace with its respective value. Because we have passed second parameter as an Array.
Replace French letters with ‘str_replace’ function
$search = array("ç","æ","œ","á","é");
$replace = array("c","ae","oe","a","e");
$string = str_replace($search, $replace, $string);
In above example str_replace function will replace all matching values of $search array with their respective key-value of $replace array.
So I am using both functions to replace French letters with their English letters.
Source: My GitHub Account