diff options
author | Thomas Lange <code@nerdmind.de> | 2017-04-29 00:58:46 +0200 |
---|---|---|
committer | Thomas Lange <code@nerdmind.de> | 2017-04-29 00:58:46 +0200 |
commit | 07eaab716f894b7668fd2aea6c3cbe81036efdf2 (patch) | |
tree | ad05ee8cf2a9e056f9825876da224e4995fe0cf4 /core/functions.php | |
parent | 6471b7d21bf571b4f1da911a5440239d0f936574 (diff) | |
download | blog-07eaab716f894b7668fd2aea6c3cbe81036efdf2.tar.gz blog-07eaab716f894b7668fd2aea6c3cbe81036efdf2.tar.xz blog-07eaab716f894b7668fd2aea6c3cbe81036efdf2.zip |
The function "makeSlugURL" has been modified and optimized.
Diffstat (limited to 'core/functions.php')
-rw-r--r-- | core/functions.php | 16 |
1 files changed, 10 insertions, 6 deletions
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); } #=============================================================================== |