Generate unique string from post header like stackoverflow
The string doesn't have to be unique, in fact: if you check the url of this post:
http://stackoverflow.com/questions/1467402/generate-a-unique-string-from-the-post-title-like-stackoverflow
The "real" unique part is the number - here 1467402
: it looks like the question ID in the database; probably some kind of auto-increment / sequence that is provided by a unique database server.
In fact, you can try checking for yourself if the "title" part is important: go to this URL:
http://stackoverflow.com/questions/1467402/glop
Even though the "title" part is clearly not here, this URL falls into this entry; -)
The "title" displayed in the URL is here for two reasons:
- more friendly urls of course
- more search engines / better for linking links.
To generate this, you need to do a couple of things:
- replace non-ascii characters; for example, "é" is likely to be translated into "e"
- replace other characters that you cannot replace nicely with "-" as word separator.
source to share
They just replace spaces with dashes, but then you'll want to make sure they don't exist yet.
If it exists, just add the number to the end.
You will notice that they have a number in front of the unique string, which will reduce the chance of collisions.
You can create this based on the Julian date (number of days in a year) and the year, for example.
source to share
If post titles are unique, just use them. Or you can create a message digest signature.
see http://www.obviex.com/samples/hash.aspx for a long answer.
source to share