Created
April 28, 2011 18:57
-
-
Save Majkl578/947036 to your computer and use it in GitHub Desktop.
webalizing string in JS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<head> | |
<script type="text/javascript"> | |
var webalize = function (str) { | |
var charlist; | |
charlist = [ | |
['Á','A'], ['Ä','A'], ['Č','C'], ['Ç','C'], ['Ď','D'], ['É','E'], ['Ě','E'], | |
['Ë','E'], ['Í','I'], ['Ň','N'], ['Ó','O'], ['Ö','O'], ['Ř','R'], ['Š','S'], | |
['Ť','T'], ['Ú','U'], ['Ů','U'], ['Ü','U'], ['Ý','Y'], ['Ž','Z'], ['á','a'], | |
['ä','a'], ['č','c'], ['ç','c'], ['ď','d'], ['é','e'], ['ě','e'], ['ë','e'], | |
['í','i'], ['ň','n'], ['ó','o'], ['ö','o'], ['ř','r'], ['š','s'], ['ť','t'], | |
['ú','u'], ['ů','u'], ['ü','u'], ['ý','y'], ['ž','z'] | |
]; | |
for (var i in charlist) { | |
var re = new RegExp(charlist[i][0],'g'); | |
str = str.replace(re, charlist[i][1]); | |
} | |
str = str.replace(/[^a-z0-9]/ig, '-'); | |
str = str.replace(/\-+/g, '-'); | |
if (str[0] == '-') { | |
str = str.substring(1, str.length); | |
} | |
if (str[str.length - 1] == '-') { | |
str = str.substring(0, str.length - 1); | |
} | |
return str.toLowerCase(); | |
} | |
alert(webalize('_Příliš žluťoučký kůň úpěl ďábelské ódy.')); | |
</script> | |
</head> | |
<body></body> | |
</html> |
ZbyRih
commented
Jun 21, 2024
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment