Library to remove diacritic signs
For various reasons you can run into situation where you have to get a clean string without accents. It might be an input query like “chèvre ou bœuf” to be converted into “chevre ou boeuf”, or it could be a string like “côté de veau cuit à cœur” that you want to display as “cote de veau cuit a coeur”.
Wouldn’t it be nice to have a simple function in php that sanitizes stings from accent signs? Here it is https://github.com/vria/nodiacritic.
Installation gets easier if you use composer:
Once installation is finished, you can use the function
The library properly treats German and Danish words if you pass an appropriate
locale. In fact, the function
filter() has two arguments:
The first argument is a string to be cleaned, and a second one is a locale, which is a standardized language name ISO 639-1. For example:
Moreover, there is [NoDiactiticBundle] that integrates this library into Symfony.
In particular, bundle adds the
nodiacritic filter to be used in twig templates:
There is no need to specify locale because bundle knows it from the current
Request object. If for some reason desirable locale differs from the
Request’s one there is a possibility to pass it:
I hope that these libraries will make your life esier.