-
-
Save reedycat/01a06607e4c49e03462f14b3a721ea98 to your computer and use it in GitHub Desktop.
Decode PHP's htmlspecialchars encoding with Javascript
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
return function(text) { | |
var map = { | |
'&': '&', | |
'&': "&", | |
'<': '<', | |
'>': '>', | |
'"': '"', | |
''': "'", | |
'’': "’", | |
'‘': "‘", | |
'–': "–", | |
'—': "—", | |
'…': "…", | |
'”': '”' | |
}; | |
return text.replace(/\&[\w\d\#]{2,5}\;/g, function(m) { return map[m]; }); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment