Unique slugs that, if fits with slug-1, slug-2… slug-n

g0d0

New Member
I am using only slug to identify a page on the website, like: example.tld/view/this-fancy-slug . This is generated from the title automatically with this function:\[code\]public static function Normalize($str){ $charset = "UTF-8"; $separator = "-"; $str = strtolower(htmlentities($str, ENT_COMPAT, $charset)); $str = preg_replace('/&(.)(acute|cedil|circ|lig|grave|ring|tilde|uml);/', "$1", $str); $str = preg_replace('/([^a-z0-9]+)/', $separator, html_entity_decode($str, ENT_COMPAT, $charset)); $str = trim($str, $separator); return $str;}\[/code\]This returns a perfect slug... but I need unique slugs. So I've to combine with mysql to check if exists a slug that fits with the created. No problem with that.The problem is that I want to add a -1 at the final if there is ONE slug. But can be buggy if are added 3 equal slugs so... how can I manage this to go from slug, slug-1, slug-2, slug-3... slug-100, slug-n?Thank you in advance!
 
Back
Top