Last active
August 29, 2015 14:09
-
-
Save xuanfeng/fc00cccec9bf89b1d34a to your computer and use it in GitHub Desktop.
html转码
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
function htmlDecode(str){ | |
return str | |
.replace(/'/g, '\'') | |
.replace(/<br\s*(\/)?\s*>/g, '\n') | |
.replace(/ /g, ' ') | |
.replace(/</g, '<') | |
.replace(/>/g, '>') | |
.replace(/"/g, '"') | |
.replace(/&/g, '&'); | |
} | |
function htmlEncode(str){ | |
return str | |
.replace(/'/g, ''') | |
.replace(/\n/g, '<br*>') | |
.replace(/\s/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