From 07eaab716f894b7668fd2aea6c3cbe81036efdf2 Mon Sep 17 00:00:00 2001 From: Thomas Lange Date: Sat, 29 Apr 2017 00:58:46 +0200 Subject: The function "makeSlugURL" has been modified and optimized. --- core/functions.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'core/functions.php') diff --git a/core/functions.php b/core/functions.php index 2e36524..89ed2f5 100644 --- a/core/functions.php +++ b/core/functions.php @@ -326,13 +326,17 @@ function description($string, $length = 200, $replace = ' […]') { #=============================================================================== # Generate a valid slug URL part from a string #=============================================================================== -function makeSlugURL($string) { - $string = mb_strtolower($string); - $string = str_replace(['ä', 'ö', 'ü', 'ß'], ['ae', 'oe', 'ue', 'ss'], $string); - $string = preg_replace('/[^a-z0-9\-]/', '-', $string); - $string = preg_replace('/-+/', '-', $string); +function makeSlugURL($string, $separator = '-') { + $string = strtr(mb_strtolower($string), [ + 'ä' => 'ae', + 'ö' => 'oe', + 'ü' => 'ue', + 'ß' => 'ss' + ]); + + $string = preg_replace('#[^[:lower:][:digit:]]+#', $separator, $string); - return trim($string, '-'); + return trim($string, $separator); } #=============================================================================== -- cgit v1.2.3