X-Git-Url: https://git.rapsys.eu/userbundle/blobdiff_plain/92c25d4b2b930bbcde1e45834878de380a6457ca..7f2857ef914109ec1a4561aea3156e6ae8424922:/Utils/Slugger.php diff --git a/Utils/Slugger.php b/Utils/Slugger.php index b3f18e2..e781fa5 100644 --- a/Utils/Slugger.php +++ b/Utils/Slugger.php @@ -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))), '-'))); } }