Skip to content

Instantly share code, notes, and snippets.

@23maverick23
Created January 5, 2013 22:18
Show Gist options
  • Save 23maverick23/4464009 to your computer and use it in GitHub Desktop.
Save 23maverick23/4464009 to your computer and use it in GitHub Desktop.
JavaScript: Simple HTML Encoder
// Encodes a string containing HTML characters
// These include &, >, <, ".
function simpleHTMLEncoder(str) {
return str.replace(/&/g, "&amp;").replace(/>/g, "&gt;").replace(/</g, "&lt;").replace(/"/g, "&quot;");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment