婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > ASP.NET過濾HTML字符串方法總結

ASP.NET過濾HTML字符串方法總結

熱門標簽:征途美甲店地圖標注 昆明語音電銷機器人價格 400電話如何申請取消 電銷語音機器人型號參數 浦發電話機器人提醒還款 太原400電話上門辦理 百度地圖怎樣做地圖標注 騰訊地圖標注手機 柳州電銷機器人公司

本文實例講述了ASP.NET過濾HTML字符串的方法,供大家參考使用,具體代碼如下:

///  summary>去除HTML標記 
///     
///  /summary>   
///  param name="Htmlstring">包括HTML的源碼/param>   
///  returns>已經去除后的文字/returns>   
public static string GetNoHTMLString(string Htmlstring) 
{ 
  //刪除腳本   
  Htmlstring = Regex.Replace(Htmlstring, @"script[^>]*?>.*?/script>", "", RegexOptions.IgnoreCase); 
  //刪除HTML   
  Htmlstring = Regex.Replace(Htmlstring, @"(.[^>]*)>", "", RegexOptions.IgnoreCase); 
  Htmlstring = Regex.Replace(Htmlstring, @"([\r\n])[\s]+", "", RegexOptions.IgnoreCase); 
  Htmlstring = Regex.Replace(Htmlstring, @"-->", "", RegexOptions.IgnoreCase); 
  Htmlstring = Regex.Replace(Htmlstring, @"!--.*", "", RegexOptions.IgnoreCase); 

  Htmlstring = Regex.Replace(Htmlstring, @"(quot|#34);", "\"", RegexOptions.IgnoreCase); 
  Htmlstring = Regex.Replace(Htmlstring, @"(amp|#38);", "", RegexOptions.IgnoreCase); 
  Htmlstring = Regex.Replace(Htmlstring, @"(lt|#60);", "", RegexOptions.IgnoreCase); 
  Htmlstring = Regex.Replace(Htmlstring, @"(gt|#62);", ">", RegexOptions.IgnoreCase); 
  Htmlstring = Regex.Replace(Htmlstring, @"(nbsp|#160);", "  ", RegexOptions.IgnoreCase); 
  Htmlstring = Regex.Replace(Htmlstring, @"(iexcl|#161);", "\xa1", RegexOptions.IgnoreCase); 
  Htmlstring = Regex.Replace(Htmlstring, @"(cent|#162);", "\xa2", RegexOptions.IgnoreCase); 
  Htmlstring = Regex.Replace(Htmlstring, @"(pound|#163);", "\xa3", RegexOptions.IgnoreCase); 
  Htmlstring = Regex.Replace(Htmlstring, @"(copy|#169);", "\xa9", RegexOptions.IgnoreCase); 
  Htmlstring = Regex.Replace(Htmlstring, @"#(\d+);", "", RegexOptions.IgnoreCase); 

  Htmlstring.Replace("", ""); 
  Htmlstring.Replace(">", ""); 
  Htmlstring.Replace("\r\n", ""); 
  Htmlstring = HttpContext.Current.Server.HtmlEncode(Htmlstring).Trim(); 

  return Htmlstring; 
} 

/// summary>獲取顯示的字符串,可顯示HTML標簽,但把危險的HTML標簽過濾,如iframe,script等。 
///  
/// /summary> 
/// param name="str">未處理的字符串/param> 
/// returns>/returns> 
public static string GetSafeHTMLString(string str) 
{ 
  str = Regex.Replace(str, @"applet[^>]*?>.*?/applet>", "", RegexOptions.IgnoreCase); 
  str = Regex.Replace(str, @"body[^>]*?>.*?/body>", "", RegexOptions.IgnoreCase); 
  str = Regex.Replace(str, @"embed[^>]*?>.*?/embed>", "", RegexOptions.IgnoreCase); 
  str = Regex.Replace(str, @"frame[^>]*?>.*?/frame>", "", RegexOptions.IgnoreCase); 
  str = Regex.Replace(str, @"script[^>]*?>.*?/script>", "", RegexOptions.IgnoreCase); 
  str = Regex.Replace(str, @"frameset[^>]*?>.*?/frameset>", "", RegexOptions.IgnoreCase); 
  str = Regex.Replace(str, @"html[^>]*?>.*?/html>", "", RegexOptions.IgnoreCase); 
  str = Regex.Replace(str, @"iframe[^>]*?>.*?/iframe>", "", RegexOptions.IgnoreCase); 
  str = Regex.Replace(str, @"style[^>]*?>.*?/style>", "", RegexOptions.IgnoreCase); 
  str = Regex.Replace(str, @"layer[^>]*?>.*?/layer>", "", RegexOptions.IgnoreCase); 
  str = Regex.Replace(str, @"link[^>]*?>.*?/link>", "", RegexOptions.IgnoreCase); 
  str = Regex.Replace(str, @"ilayer[^>]*?>.*?/ilayer>", "", RegexOptions.IgnoreCase); 
  str = Regex.Replace(str, @"meta[^>]*?>.*?/meta>", "", RegexOptions.IgnoreCase); 
  str = Regex.Replace(str, @"object[^>]*?>.*?/object>", "", RegexOptions.IgnoreCase); 
  return str; 
} 
您可能感興趣的文章:
  • asp.NET 臟字過濾算法 修改版
  • asp.NET 臟字過濾算法
  • ASP.NET過濾器的應用方法介紹
  • asp.net 過濾圖片標簽的正則
  • ASP.NET環境下為網站增加IP過濾功能
  • ASP.NET過濾HTML標簽只保留換行與空格的方法
  • ASP.NET中的URL過濾實現代碼
  • asp.net 臟字典過濾問題 用正則表達式來過濾臟數據
  • Asp.net之數據過濾淺析
  • ASP.NET過濾類SqlFilter,防止SQL注入
  • 高效.NET臟字過濾算法與應用實例

標簽:天門 江蘇 新疆 張家界 陽泉 德陽 蘭州 白山

巨人網絡通訊聲明:本文標題《ASP.NET過濾HTML字符串方法總結》,本文關鍵詞  ASP.NET,過濾,HTML,字符串,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《ASP.NET過濾HTML字符串方法總結》相關的同類信息!
  • 本頁收集關于ASP.NET過濾HTML字符串方法總結的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 留坝县| 四子王旗| 凤山县| 海宁市| 株洲市| 佛山市| 龙陵县| 德阳市| 瑞安市| 句容市| 剑川县| 察雅县| 珠海市| 嘉黎县| 望城县| 濉溪县| 中宁县| 海盐县| 桂阳县| 柏乡县| 龙川县| 八宿县| 禄劝| 静海县| 新密市| 兴安县| 张家界市| 小金县| 灵川县| 和顺县| 郯城县| 乐清市| 罗平县| 南安市| 新化县| 界首市| 连城县| 靖宇县| 西林县| 万源市| 嘉荫县|