开发者

Jquery, Convert Title to Slug

开发者 https://www.devze.com 2022-12-20 10:12 出处:网络
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 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


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"


Theres a plugin for that! :)


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

0

精彩评论

暂无评论...
验证码 换一张
取 消