From e63d9bc97a04027f2bf6b53341d47537eb261c1b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Gertz?= Date: Sun, 29 Nov 2020 08:34:11 +0100 Subject: [PATCH] Use ICU Transliterator transliterate feature when available --- Utils/Slugger.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Utils/Slugger.php b/Utils/Slugger.php index b3f18e2..9a33e6d 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))), '-'))); } } -- 2.41.1