Rapsys Git
/
userbundle
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
ff6e3ff
)
Use ICU Transliterator transliterate feature when available
author
Raphaël Gertz
<git@rapsys.eu>
Sun, 29 Nov 2020 07:34:11 +0000
(08:34 +0100)
committer
Raphaël Gertz
<git@rapsys.eu>
Sun, 29 Nov 2020 07:34:11 +0000
(08:34 +0100)
Utils/Slugger.php
patch
|
blob
|
history
diff --git
a/Utils/Slugger.php
b/Utils/Slugger.php
index b3f18e240b5ff87c25fe0929a806044651f0617f..9a33e6dca46b6b780f21411e19b9062f46ed421a 100644
(file)
--- a/
Utils/Slugger.php
+++ b/
Utils/Slugger.php
@@
-104,6
+104,11
@@
class Slugger {
//Convert string to safe slug
function slug(string $string): string {
//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))), '-')));
}
}
return preg_replace('/[\/_|+ -]+/', '-', strtolower(trim(preg_replace('/[^a-zA-Z0-9\/_|+ -]/', '', str_replace(['\'', '"'], ' ', iconv('UTF-8', 'ASCII//TRANSLIT', $string))), '-')));
}
}