]> Raphaƫl G. Git Repositories - userbundle/blobdiff - Utils/Slugger.php
Rename title in civility
[userbundle] / Utils / Slugger.php
index b3f18e240b5ff87c25fe0929a806044651f0617f..e781fa5c95e3c55e7b9a4605a3ba386053b4765e 100644 (file)
@@ -104,6 +104,11 @@ class Slugger {
 
        //Convert string to safe slug
        function slug(string $string): string {
+               //Use Transliterator if available
+               if (class_exists('Transliterator')) {
+                       $trans = Transliterator::create('Any-Latin; Latin-ASCII; Lower()');
+                       return preg_replace(['/[^a-zA-Z0-9]+/', '/(^-+|-+$)/'], ['-', ''], $trans->transliterate($string));
+               }
                return preg_replace('/[\/_|+ -]+/', '-', strtolower(trim(preg_replace('/[^a-zA-Z0-9\/_|+ -]/', '', str_replace(['\'', '"'], ' ', iconv('UTF-8', 'ASCII//TRANSLIT', $string))), '-')));
        }
 }