Replace French letters with their English letters

translate

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:


  1. strtr — Translate characters or replace substrings
  2. str_replace — Replace all occurrences of the search string with the replacement string

Replace French letters with ‘strtr’ function

Translating the letters:

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

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

Leave a Reply