There are a few answers here on SO regarding this issue, but when I tried them in the past, it seemed that most of them were too dependant on the locale of the system or even str_replace with incomplete arrays. So running the code would either create different results on different environment or would miss a couple of characters.
In the end I found the best approach comes from this non-accepted answer. From my tests this approach works perfectly, independently from all local settings, and can be adapted for accents only è
or different sets like æ
The base is the Transliterator class, part of the intl extension. which is available from PHP 5.4 onwards. In most system it's either already bundled or can be installed with
pecl install intl`
More installation info here.
Usage
How to use is quite straightforward
- Step 1: you initialise the Transliterator object
$transliterator = Transliterator::createFromRules(':: NFD; :: [:Nonspacing Mark:] Remove; :: NFC;', Transliterator::FORWARD);
For a list of rules that can be applied to this function, please refer to this manual. The ones used in the example already work for your specific use case.
- Step 2: you use it to transliterate your text
$newstring = $transliterator->transliterate($string);
In your specific case, you need of course to apply to all the relevant elements of your array.
You're not sharing the array structure, so I can not produce a clear example, but depending on the structure you can use foreach
or array_walk or recursive functions to loop and change where needed.
If you want to update your initial question with a sample from the array, we can be more precise.