Created
August 14, 2011 15:01
-
-
Save dtinth/1144953 to your computer and use it in GitHub Desktop.
Decode UTF-8 characters in URLs. Pass the second argument as true to make it output as &#charcode; instead of the character.
This file contains hidden or 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
function decodeUTF(x, z) { | |
return x.replace(/%([cd][0-9a-f]%[89ab][0-9a-f]|e[0-9a-f](?:%[89ab][0-9a-f]){2}|f[0-7](?:%[89ab][0-9a-f]){3}|f[89ab](?:%[89ab][0-9a-f]){4}|f[cd](?:%[89ab][0-9a-f]){5})/ig, function(a) { | |
return z ? '&#' + decodeURIComponent(a).charCodeAt(0) + ';' : decodeURIComponent(a); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment