挖客网

asp.net 过滤所有html标识函数

挖客dodo 发表于2008-11-7 15:17:39 来源:原创
您现在正在浏览:首页 »Net编程

//添加文章过滤
    public string checkStr(string html)
    {
        System.Text.RegularExpressions.Regex regex1 =
            new System.Text.RegularExpressions.Regex(@"<script[\s\S]+</script *>",
                System.Text.RegularExpressions.RegexOptions.IgnoreCase);
        System.Text.RegularExpressions.Regex regex2 =
            new System.Text.RegularExpressions.Regex(@" href *= *[\s\S]*script *:",
                System.Text.RegularExpressions.RegexOptions.IgnoreCase);
        System.Text.RegularExpressions.Regex regex3 =
            new System.Text.RegularExpressions.Regex(@" no[\s\S]*=",
                System.Text.RegularExpressions.RegexOptions.IgnoreCase);
        System.Text.RegularExpressions.Regex regex4 =
            new System.Text.RegularExpressions.Regex(@"<iframe[\s\S]+</iframe *>",
                System.Text.RegularExpressions.RegexOptions.IgnoreCase);
        System.Text.RegularExpressions.Regex regex5 =
            new System.Text.RegularExpressions.Regex(@"<frameset[\s\S]+</frameset *>",
                System.Text.RegularExpressions.RegexOptions.IgnoreCase);
        System.Text.RegularExpressions.Regex regex6 =
                    new System.Text.RegularExpressions.Regex(@"\<img[^\>]+\>",
                        System.Text.RegularExpressions.RegexOptions.IgnoreCase);
        System.Text.RegularExpressions.Regex regex7 =
            new System.Text.RegularExpressions.Regex(@"</p>",
                System.Text.RegularExpressions.RegexOptions.IgnoreCase);
        System.Text.RegularExpressions.Regex regex8 =
            new System.Text.RegularExpressions.Regex(@"<p>",
                System.Text.RegularExpressions.RegexOptions.IgnoreCase);
        System.Text.RegularExpressions.Regex regex9 =
            new System.Text.RegularExpressions.Regex(@"<[^>]*>",
                System.Text.RegularExpressions.RegexOptions.IgnoreCase);
        html = regex1.Replace(html, ""); //过滤<script></script>标记
        html = regex2.Replace(html, ""); //过滤href=javascript: (<A>) 属性
        html = regex3.Replace(html, " _disibledevent="); //过滤其它控件的on...事件
        html = regex4.Replace(html, ""); //过滤iframe
        html = regex5.Replace(html, ""); //过滤frameset
        html = regex6.Replace(html, ""); //过滤frameset
        html = regex7.Replace(html, ""); //过滤frameset
        html = regex8.Replace(html, ""); //过滤frameset
        html = regex9.Replace(html, "");
        html = html.Replace(" ", "");
        html = html.Replace("</strong>", "");
        html = html.Replace("<strong>", "");
        return html;
    }
标签:无标签 推荐给好友
最近关注的注册会员
回复»asp.net 过滤所有html标识函数 点评推荐五笔拼音输入法
 请大家保持房间整洁,爱护花花草草,文明发言
发言前,请仔细阅读并同意以下注意事项,未注册用户请点击 注册
1.请尊重网上道德;
2.遵守 互联网电子公告服务管理规定 及中华人民共和国其他各项有关法律法规;
3.严禁发表危害国家安全、破坏民族团结、破坏国家宗教政策、破坏社会稳定、侮辱、诽谤、教唆、淫秽等内容的作品;
4.承担一切因您的行为而直接或间接导致的民事或刑事法律责任。
5.挖客网所有帖子仅代表作者本人意见,不代表本站立场。
dodo
加为好友 发短信息
文 章:194篇 积分:6170
自 述:欢迎使用diggcms开源内容管理系统 [更多>>]
最新发布 · · · · · ·
热门Tags · · · · · ·
>最新评论