过滤方法

private String HtmlCode(string TString)
    {
        if (TString != null)
        {
            TString = TString.Replace("\r", "<br>");
            //TString = TString.Replace(" ", "&nbsp;");
            TString = TString.Replace("<script>", "&lt;script&gt;");
            TString = TString.Replace("</script>", "&lt;/script&gt;");
            TString = TString.Replace("<script language=javascript>", "&lt;script language=javascript&gt;&lt;/script&gt;");
            //TString = TString.Replace("&nbsp;", " ");
           
            //System.Text.RegularExpressions.Regex regex1 = new System.Text.RegularExpressions.Regex(@"<script[sS]+< /script *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);

            //System.Text.RegularExpressions.Regex regex2 = new System.Text.RegularExpressions.Regex(@" href *= *[sS]*script *:", System.Text.RegularExpressions.RegexOptions.IgnoreCase);

            //System.Text.RegularExpressions.Regex regex3 = new System.Text.RegularExpressions.Regex(@" on[sS]*=", System.Text.RegularExpressions.RegexOptions.IgnoreCase);

            //System.Text.RegularExpressions.Regex regex4 = new System.Text.RegularExpressions.Regex(@"<iframe[sS]+</iframe *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);

            //System.Text.RegularExpressions.Regex regex5 = new System.Text.RegularExpressions.Regex(@"<frameset[sS]+</frameset *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);

            //TString = regex1.Replace(TString, ""); //过滤< script>< /script>标记

            //TString = regex2.Replace("", TString); //过滤href=javascript: (< A>) 属性

            //TString = regex3.Replace(" _disibledevent=",TString); //过滤其它控件的on...事件

            //TString = regex4.Replace("", TString); //过滤iframe

            //TString = regex5.Replace("", TString); //过滤frameset


            //TString = TString.Replace("", " ");
            return TString;
        }
        else
        {
            return TString = "无内容";
        }
    }

posted @ 2009-06-10 19:39  BeamWen  阅读(95)  评论(0编辑  收藏  举报