What language are you using? Because you posted here I think you are not using PHP, and if so, I think this can be useful as well
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
function sym(el){
var res="";
var l="";
var i; i=0;
var s= document.getElementById(el).value;
while (i<=s.length){
var l= s.substr(i,1);
switch(l){
case '<':
l = '<';
res = res + l;
break;
case '>':
l = '>';
res = res + l;
break;
default:
res = res + l;
}
i++;
}
}
</script>
</head>
<body>
<textarea id="area" onchange = "sym(id);"></textarea>
</body>
</html>
HTH.