JavaScript Tutorial HTML illegal character filtering and conversion functions
< Meta http-equiv= "Content-type" content= "text/html;" charset=gb2312 "/>
<title></title>
<script language= "JavaScript" >
function Htmlspecialchars (str) {
return Preg_replace ([' & ', ' < ', ' > ', ' "'], [' & ', ' < ', ' > ', ' " '], str);
}
function enhtml (str)
{
return Preg_replace ([' ', ' < ', ' > ', ' & '], [', ' < ', ' > ', ' & '], str);
}
function htmltohtml ()
{
$ ("T2"). Value =htmlspecialchars ($ ("T1"). Value);
}
function Htmltoa ()
{
$ ("T1"). Value =htmlspecialchars ($ ("T2"). Value);
}
function $ (ID)
{
return document.getElementById (ID);
}
</script>
<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>