A PHP library to remove accents and diacritics from strings.
composer require codeinc/strip-accentsRequires PHP 8.2 or later with the mbstring extension.
use CodeInc\StripAccents\StripAccents;
echo StripAccents::strip("C'est une super chaîne de caractères avec beaucoup d'accents");
// "C'est une super chaine de caracteres avec beaucoup d'accents"
echo StripAccents::strip("ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿ");
// "AAAAAACEEEEIIIIOOOOOUUUUYaaaaaaceeeeiiiieooooouuuuyy"use CodeInc\StripAccents\StripAccents;
echo StripAccents::stripNonPrint("ABC ÀÈÝ 是我这");
// "ABC AEY "
echo StripAccents::stripNonPrint("ABC ÀÈÝ 是我这", replaceWith: "-");
// "ABC AEY ---------" (each multibyte character is replaced per-byte)Both methods accept an encoding parameter (any encoding supported by htmlentities()):
echo StripAccents::strip("A strïng with àccénts", encoding: "iso-8859-1");This library is published under the MIT license (see the LICENSE file).