I am trying to get unique titles in article posts in a system. Whilst I've been developing it, I know that people may re-use article titles, so I'm trying to develop a way around it. At the minute, I'm down to this:
But, what happens if something with the same url_name exists? What is the most efficent way of tagging a number onto the end? It could loop through the strings, but, would it be better to put the next available ID at the end of the title? This raises another question, how can I find out what the next ID is actually going to be for MySQL with PHP? If the record was deleted from the db, the latest record + 1 will not give me the answer?
$title_lower = strtolower($title);
$title_sanitized = preg_replace("/[^a-zA-Z0-9[:blank:]s]/", "", $title_lower);
$title_exploded_url = explode(" ", $title_sanitized);
$url_name = implode("-", $title_exploded_url);
Thanks in advance,