PHP Application check name is unique if not append

Posted by user270797 on Stack Overflow See other posts from Stack Overflow or by user270797
Published on 2010-05-24T07:10:11Z Indexed on 2010/05/24 7:11 UTC
Read the original article Hit count: 290

Filed under:
|
|
|
|

My application requires the user to enter their business name, which the application will automatically create into a unique identifier to be used in URLs, ie

"Bob's Cafe" will become "bobs-cafe"

But if there are duplicate names I would like the application to add a number so if there is already a "bobs-cafe" we will use "bobs-cafe-1" and likewise if there is already a "bobs-cafe-1" we will use "bobs-cafe-2"

Ive used explode and also looked at a regular expressions but I dont know the best way to approach this.

Im stuck in being able to grab the number and incrementing it and returning the string

© Stack Overflow or respective owner

Related posts about php

Related posts about unique