/// <summary>
/// 去除HTML标签
/// </summary>
/// <param name="s"></param>
/// <returns></returns>
public static string RemoveHTMLTags(string s)
{
//删除脚本
s = Regex.Replace(s, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase);
//删除HTML
s = Regex.Replace(s, @"<(.[^>]*)>", "", RegexOptions.IgnoreCase);
s = Regex.Replace(s, @"([/r/n])[/s]+", "", RegexOptions.IgnoreCase);
s = Regex.Replace(s, @"-->", "", RegexOptions.IgnoreCase);
s = Regex.Replace(s, @"<!--.*", "", RegexOptions.IgnoreCase);
s = Regex.Replace(s, @"&(quot|#34);", "/"", RegexOptions.IgnoreCase);
s = Regex.Replace(s, @"&(amp|#38);", "&", RegexOptions.IgnoreCase);
s = Regex.Replace(s, @"&(lt|#60);", "<", RegexOptions.IgnoreCase);
s = Regex.Replace(s, @"&(gt|#62);", ">", RegexOptions.IgnoreCase);
s = Regex.Replace(s, @"&(nbsp|#160);", " ", RegexOptions.IgnoreCase);
s = Regex.Replace(s, @"&(iexcl|#161);", "/xa1", RegexOptions.IgnoreCase);
s = Regex.Replace(s, @"&(cent|#162);", "/xa2", RegexOptions.IgnoreCase);
s = Regex.Replace(s, @"&(pound|#163);", "/xa3", RegexOptions.IgnoreCase);
s = Regex.Replace(s, @"&(copy|#169);", "/xa9", RegexOptions.IgnoreCase);
s = Regex.Replace(s, @"&#(/d+);", "", RegexOptions.IgnoreCase);
s.Replace("<", "");
s.Replace(">", "");
s.Replace("/r/n", "");
s = HttpContext.Current.Server.HtmlEncode(s).Trim();
return s;
}
去除HTML标签
最新推荐文章于 2024-04-26 10:32:50 发布