/ Published in: JavaScript
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function slugify(s) { //s = 'Was wäre daß® für ein + unnützer Tést?'; var slug = s; slug = slug.toLowerCase(); slug = slug.replace(/\s+/g,'-'); tr = { '\u00e4':'ae', '\u00fc':'ue', '\u00f6':'oe', '\u00df':'ss', '\u00df':'ss', '\u00e9':'e', '/':'-' } for ( var key in tr ) { slug = slug.replace(new RegExp(key, 'g'), tr[key]); } slug = slug.replace(/[^a-zA-Z0-9\-]/g,''); slug = slug.replace(/-+/g, '-'); //alert(slug); // return(s); return slug; }