Created
May 10, 2011 02:38
-
-
Save mocheng/963826 to your computer and use it in GitHub Desktop.
Different Implementation of escapeHTML
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 escapeHTML(s) { | |
return s.replace(/&/g, '&').replace(/>/g, '>').replace(/</g,'<').replace(/"/g, '"').replace(/'/g,''').replace(/\//g,'/'); | |
} |
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 escapeHTML(s) { | |
r={'&':'&','>':'>','<':'<','"':'"','\'':''','/':'/'}; | |
return s.replace(/./g, function(m){return r[m]?r[m]:m}) | |
} |
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 escapeHTML(s) { | |
r='replace';return s[r](/&/g,'&')[r](/>/g,'>')[r](/</g,'<')[r](/"/g, '"')[r](/'/g,''')[r](/\//g,'/'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment