Converting umlaute with symfony String component

There are multiple PHP native ways to convert umlaute and other special characters to ascii save formats, but most of them i experience insufficient in the one or other way.

Since i am using symfony anyway i can use the String component which has a handy slugger which converts any characters into safe ascii characters.
It is very flexible and can be customized with locales, custom replacements and closures.

$umlautString = "Müller Meier";
$slugger = new Symfony\Component\String\Slugger\AsciiSlugger('de');
$slugger->slug($umlautString, $seperator = ' ')->toString();
echo $umlautString; // mueller meierCode language: PHP (php)

I guess this will become my go-to method resp. slugger to convert umlaute in any PHP application.

Continue reading “Converting umlaute with symfony String component”