Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Different Implementation of escapeHTML
function escapeHTML(s) {
return s.replace(/&/g, '&amp;').replace(/>/g, '&gt;').replace(/</g,'&lt;').replace(/"/g, '&quot').replace(/'/g,'&#x27;').replace(/\//g,'&#x2F;');
}
function escapeHTML(s) {
r={'&':'&amp;','>':'&gt;','<':'&lt;','"':'&quot;','\'':'&#x27;','/':'&#x2f'};
return s.replace(/./g, function(m){return r[m]?r[m]:m})
}
function escapeHTML(s) {
r='replace';return s[r](/&/g,'&amp;')[r](/>/g,'&gt;')[r](/</g,'&lt;')[r](/"/g, '&quot')[r](/'/g,'&#x27;')[r](/\//g,'&#x2F;');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment