From dbed89499b93b2ec3c2c50e5805ef8393a8ef990 Mon Sep 17 00:00:00 2001 From: MaZderMind Date: Wed, 21 Dec 2016 18:22:37 +0100 Subject: work on startpage style --- lib/helper.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'lib') 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; +} -- cgit v1.2.3