diff options
Diffstat (limited to '')
-rw-r--r-- | lib/helper.php | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/helper.php b/lib/helper.php index 1925382..67c84aa 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -145,3 +145,30 @@ function array_filter_last($array, $predicate) return null; } + +function slugify($text) +{ + // replace non letter or digits by - + $text = preg_replace('~[^\pL\d]+~u', '-', $text); + + // transliterate + $text = iconv('utf-8', 'us-ascii//TRANSLIT', $text); + + // remove unwanted characters + $text = preg_replace('~[^-\w]+~', '', $text); + + // trim + $text = trim($text, '-'); + + // remove duplicate - + $text = preg_replace('~-+~', '-', $text); + + // lowercase + $text = strtolower($text); + + if (empty($text)) { + return 'none'; + } + + return $text; +} |