熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

詳解ASP.NET清除HTML標記的函數

2022-06-13   來源: .NET編程 
//清除HTML函數 
    public static string NoHTML(string Htmlstring) 
    { 
        //刪除腳本 
        Htmlstring = RegexReplace(Htmlstring @<script[^>]*?>*?</script> RegexOptionsIgnoreCase); 
        //刪除HTML 
        Htmlstring = RegexReplace(Htmlstring @<([^>]*)> RegexOptionsIgnoreCase); 
        Htmlstring = RegexReplace(Htmlstring @([\r\n])[\s]+ RegexOptionsIgnoreCase); 
        Htmlstring = RegexReplace(Htmlstring @> RegexOptionsIgnoreCase); 
        Htmlstring = RegexReplace(Htmlstring @<!* RegexOptionsIgnoreCase); 
        Htmlstring = RegexReplace(Htmlstring @&(quot|#); \ RegexOptionsIgnoreCase); 
        Htmlstring = RegexReplace(Htmlstring @&(amp|#); & RegexOptionsIgnoreCase); 
        Htmlstring = RegexReplace(Htmlstring @&(lt|#); < RegexOptionsIgnoreCase); 
        Htmlstring = RegexReplace(Htmlstring @&(gt|#); > RegexOptionsIgnoreCase); 
        Htmlstring = RegexReplace(Htmlstring @&(nbsp|#); RegexOptionsIgnoreCase); 
        Htmlstring = RegexReplace(Htmlstring @&(iexcl|#); \xa RegexOptionsIgnoreCase); 
        Htmlstring = RegexReplace(Htmlstring @&(cent|#); \xa RegexOptionsIgnoreCase); 
        Htmlstring = RegexReplace(Htmlstring @&(pound|#); \xa RegexOptionsIgnoreCase); 
        Htmlstring = RegexReplace(Htmlstring @&(copy|#); \xa RegexOptionsIgnoreCase);          Htmlstring = RegexReplace(Htmlstring @&#(\d+); RegexOptionsIgnoreCase);
        HtmlstringReplace(< );
        HtmlstringReplace(> );
        HtmlstringReplace(\r\n );
       Htmlstring = HttpContextCurrentServerHtmlEncode(Htmlstring)Trim();
        return Htmlstring;
    }
From:http://tw.wingwit.com/Article/program/net/201311/15282.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.