Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
function htmlEntities(str) {
return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');

This comment has been minimized.

Copy link

@jdalton jdalton commented Sep 14, 2010

Doesn't handle quotes but can handle many more entities...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment