javascript htmlspecialchars code example
Example 1: htmlspecialchars
<?php
$new = htmlspecialchars("<a href='test'>Test</a>", ENT_QUOTES);
echo $new;
?>
Example 2: htmlspecialchars for jsp
StringBuffer sb = new StringBuffer();
for(int i=0; i<content.length(); i++){
char c = content.charAt(i);
switch (c) {
case '<' :
sb.append("<");
break;
case '>' :
sb.append(">");
break;
case '&' :
sb.append("&");
break;
case '"' :
sb.append(""");
break;
case '\'' :
sb.append("'");
break;
default:
sb.append(c);
}
}