JavaScript Tutorial HTML illegal character filtering and conversion functions
<html xmlns= "http://www.jzread.com/1999/xhtml" >
<head>
<meta http-equiv= "Content-type" content= "HTML; charset=gb2312 "/>
<title>javascript HTML illegal character filtering and conversion function </title>
<script language= "JavaScript" >
function Htmlspecialchars (str) {
return Preg_replace ([' & ', ' < ', ' > ', ' "'], [' &amp; ', ' &lt; ', ' &gt; ', ' &quot; '], str);
}
function enhtml (str)
{
return Preg_replace ([' &nbsp; ', ' &lt; ', ' &gt; ', ' &amp; '], [', ' < ', ' > ', ' & '], str);
}
function htmltohtml ()
{
$ ("T2"). Value =htmlspecialchars ($ ("T1"). Value);
}
function Htmltoa ()
{
$ ("T1"). Value =htmlspecialchars ($ ("T2"). Value);
}
function $ (ID)
{
return document.getElementById (ID);
}
</script>
</head>
<body>
<p> </p>
<form id= "Form1" Name= "Form1" method= "Post" action= "" >
<label>
<textarea name= "T1" cols= "rows=" "id=" T1 "></textarea>
<br/>
<br/>
<input type= "button" Name= "Submit" value= "Convert to HTML Encoding" onclick= "htmltohtml ();"/>
</label>
<label>
<input type= "button" Name= "Submit2" value= "into HTML tags" onclick= "Htmltoa ();"/>
</label>
<p>
<textarea name= "T2" cols= "rows=" "id=" T2 "></textarea>
</p>
</form>
</body>
</html>