Encode HTML string - Node.js String

Node.js examples for String:HTML String

Description

Encode HTML string

Demo Code


function encodeHTML(source) {
    return String(source)
        .replace(/&/g, '&')
        .replace(/</g, '&lt;')
        .replace(/>/g, '&gt;')
        .replace(/"/g, '&quot;')
        .replace(/'/g, '&#39;');
}

Related Tutorials