I'm writing a small CMS and I'm trying to turn a title into a URL slug with dashes. I know I need to do a couple of things and I've got the whole thing work, but I just don't like it. The problem seems to be that if there are any special characters at the end, I'd need to remove them before it goes into the database. The only way I could figure out doing this was to do 2 preg_replace's in one statement. So it looks something like this:
preg_replace("/\-$/","",preg_replace('/[^a-z0-9]+/i', "-", strtolower($title)));
and it and turn this: (this is a title!!!)))**that is (strange))
into this: this-is-a-title-that-is-strange
But this expression just looks like ass. There has to be a better way of coding this, or something out there, I just don't know it. Any help would be greatly appreciated