最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

ASP.NET過濾HTML字符串方法總結(jié)

 更新時間:2014年08月06日 11:26:32   投稿:shichen2014  
這篇文章主要介紹了ASP.NET過濾HTML字符串方法總結(jié),需要的朋友可以參考下

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

///  <summary>去除HTML標(biāo)記 
///     
///  </summary>   
///  <param name="Htmlstring">包括HTML的源碼</param>   
///  <returns>已經(jīng)去除后的文字</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標(biāo)簽,但把危險的HTML標(biāo)簽過濾,如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; 
} 

相關(guān)文章

最新評論

九龙坡区| 莆田市| 开远市| 永川市| 武穴市| 民和| 乌兰察布市| 永定县| 淅川县| 屯昌县| 古丈县| 嘉禾县| 松溪县| 全椒县| 随州市| 武穴市| 中牟县| 凤冈县| 肃南| 扶风县| 波密县| 水城县| 顺昌县| 泾阳县| 上虞市| 河曲县| 民乐县| 汾西县| 新宾| 青川县| 百色市| 武义县| 环江| 平塘县| 壤塘县| 阿拉善左旗| 赣榆县| 白沙| 纳雍县| 永仁县| 乐都县|