19 lines
503 B
JavaScript
19 lines
503 B
JavaScript
function escape_html(str) {
|
|
|
|
if ((str===null) || (str===''))
|
|
return false;
|
|
else
|
|
str = str.toString();
|
|
|
|
var map = {
|
|
'&': '&',
|
|
'<': '<',
|
|
'>': '>',
|
|
'"': '"',
|
|
"'": '''
|
|
};
|
|
|
|
return str.replace(/[&<>"']/g, function(m) { return map[m]; });
|
|
}
|
|
console.log(escape_html('PHP & MySQL'));
|
|
console.log(escape_html('3 > 2'));
|