public string ClearHtml(string text)//过滤html,js,css代码
    {
        text = text.Trim();
        if (string.IsNullOrEmpty(text))
            return string.Empty;
        text = Regex.Replace(text, "<head[^>]*>(?:.|[\r\n])*?</head>", "");
        text = Regex.Replace(text, "<script[^>]*>(?:.|[\r\n])*?</script>", "");
        text = Regex.Replace(text, "<style[^>]*>(?:.|[\r\n])*?</style>", "");
        
        text = Regex.Replace(text, "(<[b|B][r|R]/*>)+|(<[p|P](.|\\n)*?>)", ""); //<br> 
        text = Regex.Replace(text, "\\&[a-zA-Z]{1,10};", "");
        text = Regex.Replace(text, "<[^>]*>", "");

        text = Regex.Replace(text, "(\\s*&[n|N][b|B][s|S][p|P];\\s*)+", ""); // 
        text = Regex.Replace(text, "<(.|\\n)*?>", string.Empty); //其它任何标记
        text = Regex.Replace(text, "[\\s]{2,}", " "); //两个或多个空格替换为一个

        text = text.Replace("'", "''");
        text = text.Replace("\r\n", "");
        text = text.Replace("  ", "");
        text = text.Replace("\t", "");
        return text.Trim();
    }

  

相关文章:

  • 2022-01-27
  • 2021-04-07
  • 2021-07-26
  • 2022-12-23
  • 2021-12-01
  • 2021-07-15
猜你喜欢
  • 2021-06-29
  • 2021-11-20
  • 2022-12-23
  • 2022-01-03
  • 2022-12-23
  • 2022-12-23
  • 2021-11-20
相关资源
相似解决方案