How to check if the string contains any tags <>. I need to sanitize my string from xss attacks or attacks like that. I am looking for a function which can santize my string in javascript and php.
This is what I have for java script , please let me know if this is correct ?
function parseThisString(strcode) {
var scripts = new Array();
while(strcode.indexOf("<") > -1 || strcode.indexOf("</") > -1) {
var s = strcode.indexOf("<");
var s_e = strcode.indexOf(">", s);
var e = strcode.indexOf("</", s);
var e_e = strcode.indexOf(">", e);
scripts.push(strcode.substring(s_e+1, e));
strcode = strcode.substring(0, s) + strcode.substring(e_e+1);
}
if (scripts.length > 0) { return 1; } else { return 0; }
}
Can you guys show me any solid string sanitizing function in php ? I found this answer but I didt know how to transilate this function to a single return with 0 or 1 (yes or no) . What is the correct way to detect whether string inputs contain HTML or not?
Please help me here . Thanks.