willbeeler
willbeeler

Reputation: 689

Jquery, Convert Title to Slug

I have a PHP script that does the following: It takes a string, for example, "This is a Great Blog Post, #1!", and returns the following string, "this-is-a-great-blog-post-1".

I'm not exactly a Jquery expert, that's why I'm asking this question. Does someone know of a Jquery (or Javascript, for that matter) script that will do the same thing as my script? Thanks in advance.

Will

Upvotes: 3

Views: 5458

Answers (3)

Mirko
Mirko

Reputation: 5286

Try this one slugit-jquery, it has decent multilanguage support.

Upvotes: 2

Erik
Erik

Reputation: 20722

Or you could write your own version in about 45 seconds:

var str = "This is a Great Blog Post, #1!";
str = str.replace(/[^a-zA-Z0-9\s]/g,"");
str = str.toLowerCase();
str = str.replace(/\s/g,'-');
document.write(str);

// outputs "this-is-a-great-blog-post-1"

Upvotes: 15

Francisco Aquino
Francisco Aquino

Reputation: 9127

Theres a plugin for that! :)

Upvotes: 5

Related Questions