Slug ID's with the same name?

Posted by James Jeffery on Stack Overflow See other posts from Stack Overflow or by James Jeffery
Published on 2010-06-06T22:04:32Z Indexed on 2010/06/06 22:32 UTC
Read the original article Hit count: 474

Filed under:
|
|

I want to create slug URL's from a users title in my system.

If a user types "The best way's to get slim; period!", then I want the slug to be "the-best-ways-to-get-slim-period".

Also, if someone has already created a page with that title I want the slug to be "the-best-ways-to-get-slim-period-1".

My question is how can I check the database before a record is created? Ok, obviously I am going to have to perform a check in the database, and then a write. That's 2 queries. Is this the normal way to do it?

Also, are there any conventional regular expressions for filtering non alpha/number characters and replacing spaces with hyphens?

Any help is much appreciated.

Thanks.

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql