zoukankan      html  css  js  c++  java
  • 过滤字符串的Html标记 c#函数 .

     1 01.public static string StripHTML(string strHtml)  
     2 02.   {  
     3 03.       string[] aryReg ={     
     4 04.                     @"<script[^>]*?>.*?</script>",     
     5 05.     
     6 06.                     @"<(/s*)?!?((w+:)?w+)(w+(s*=?s*(([""'])(\[""'tbnr]|[^7])*?7|w+)|.{0})|s)*?(/s*)?>",     
     7 07.                     @"([
    ])[s]+",     
     8 08.                     @"&(quot|#34);",     
     9 09.                     @"&(amp|#38);",     
    10 10.                     @"&(lt|#60);",     
    11 11.                     @"&(gt|#62);",       
    12 12.                     @"&(nbsp|#160);",       
    13 13.                     @"&(iexcl|#161);",     
    14 14.                     @"&(cent|#162);",     
    15 15.                     @"&(pound|#163);",     
    16 16.                     @"&(copy|#169);",     
    17 17.                     @"&#(d+);",     
    18 18.                     @"-->",     
    19 19.                     @"<!--.*
    "     
    20 20.                   };  
    21 21.  
    22 22.       string[] aryRep =   {     
    23 23.                       "",     
    24 24.                       "",     
    25 25.                       "",     
    26 26.                       """,     
    27 27.                       "&",     
    28 28.                       "<",     
    29 29.                       ">",     
    30 30.                       "   ",     
    31 31.                       "xa1",     
    32 32.                       "xa2",     
    33 33.                       "xa3",     
    34 34.                       "xa9",     
    35 35.                       "",     
    36 36.                       "
    ",     
    37 37.                       ""     
    38 38.                     };  
    39 39.  
    40 40.       string newReg = aryReg[0];  
    41 41.       string strOutput = strHtml;  
    42 42.       for (int i = 0; i < aryReg.Length; i++)  
    43 43.       {  
    44 44.           Regex regex = new Regex(aryReg[i], RegexOptions.IgnoreCase);  
    45 45.           strOutput = regex.Replace(strOutput, aryRep[i]);  
    46 46.       }  
    47 47.       strOutput.Replace("<", "");  
    48 48.       strOutput.Replace(">", "");  
    49 49.       strOutput.Replace("
    ", "");  
    50 50.       return strOutput;  
    51 51.   }
    View Code
  • 相关阅读:
    虚拟机添加新磁盘挂载,导致以前的文件丢失解决办法
    python实现tab键自动补全
    设计模式
    js 深浅拷贝 笔记总结
    js 闭包
    flex 布局
    vue2.0 之 生命周期
    移动端适配 rem
    vue 之 双向绑定原理
    vue2.0 之 过渡动画transtion
  • 原文地址:https://www.cnblogs.com/yangpeng-jingjing/p/3851652.html
Copyright © 2011-2022 走看看