JavaScript: htmlEntities

Published on Author craigzearfossLeave a comment

/*
Replaces html entities.
*/

function htmlEntities(str) {
    return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
}

Leave a Reply

Your email address will not be published. Required fields are marked *