Created
September 18, 2013 02:51
-
-
Save xu33/6603865 to your computer and use it in GitHub Desktop.
html encode and decode
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 htmlEscape(str) { | |
return String(str) | |
.replace(/&/g, '&') | |
.replace(/"/g, '"') | |
.replace(/'/g, ''') | |
.replace(/</g, '<') | |
.replace(/>/g, '>'); | |
} | |
function htmlUnescape(value){ | |
return String(value) | |
.replace(/"/g, '"') | |
.replace(/'/g, "'") | |
.replace(/</g, '<') | |
.replace(/>/g, '>') | |
.replace(/&/g, '&'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment