i have code want convert html entities [ &, <, >, ",' ] however, failing these 2 <>, on debugger, test becomes false, if switch them, first 1 works? code same ",' , why <> don't work?
function converthtml(str) { // :) var = /[&]/ig; var b = /[><><<>><]/ig; var c = /["']/ig; var e = str.split(''); var t = []; function qw(item) { return (item == '>') ? '>' : '<'; } function fg(item) { return (item == '"') ? '"' : '''; } (var x = 0; x < e.length; x++) { var cv = e[x]; if (a.test(cv)) { cv = '&'; t.push(cv); } else if (b.test(cv)) { var er = qw(cv); // invoke function, error here, on second iteration t.push(er); } else if (c.test(cv)) { var df = fg(cv); t.push(df); } else { t.push(cv); } } return t.join(''); } converthtml("><");
Comments
Post a Comment