function htmlspecialchars(str) { str = str.replace(/&/gi, '&'); str = str.replace(/"/gi, '"'); str = str.replace(/</gi, '<'); str = str.replace(/>/gi, ">"); return str; } //alert(htmlspecialchars("<<script>alert(\"I'm a pig.\");</sc")); function htmlspecialchars_decode(str) { str = str.replace(/"/gi, '"'); str = str.replace(/</gi, '<'); str = str.replace(/>/gi, '>'); str = str.replace(/&/gi, "&"); return str; } /*alert(htmlspecialchars_decode("&lt;script>alert("I'm a pig.");</sc <br> <script>alert('a');</script>"));*/
|