Skip to content

Instantly share code, notes, and snippets.

@adamplabarge
Created July 29, 2016 18:18
Show Gist options
  • Save adamplabarge/cc0d0c4020a257323b3971d1a19d20bf to your computer and use it in GitHub Desktop.
Save adamplabarge/cc0d0c4020a257323b3971d1a19d20bf to your computer and use it in GitHub Desktop.
function htmlEncode(str) {
return str.replace(/&/g, '&')
.replace(/"/g, '"')
.replace(/'/g, ''')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment