htmlEntities for JavaScript
htmlentities()
is a PHP function which converts special characters (like <) into their escaped/encoded values (like <). This allows you to show to display the string without the browser reading it as HTML.
function htmlEntities(str) {
return String(str).replace(/&/g, '&').replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"');
}