function Htmlspecialchars (str) {
str = str.replace (/&/g, ' & ');
str = str.replace (/</g, ' < ');
str = str.replace (/>/g, ' > ');
str = str.replace (/"/g, ' " ');
str = str.replace (/'/g, ' & #039; ');
return str;
}
This version is more than a few things translated
function Htmlspecialchars (str) {
var s = "";
if (Str.length = = 0) return "";
for (var i=0; i<str.length; i++)
{
Switch (STR.SUBSTR (i,1))
{
Case "<": s + = "<"; Break
Case ">": S + = ">"; Break
Case "&": S + = "&"; Break
Case "":
if (str.substr (i + 1, 1) = = "") {
s + = " ";
i++;
} else S + = "";
Break
Case "\" ": s + =" " "; Break
Case "\ n": s + = "<br>"; Break
Default:s + = Str.substr (i,1); Break
}
}
return s;
}
JS converts a pre-defined HTML string into an HTML entity htmlspecialchars output HTML entity content including tags, not automatically escaped labels, only display content, PHP-like Htmlspecialchars