ASP怎样才能把内容中的HTML去掉

ASP怎样才能把内容中的HTML去掉,第1张

<[/]?[a-zA-Z]+>

过滤HTML标签

或者用repalce 函数替换,比如我要把变量x中的所有<去掉

那么就是x=replace(x,"<","")

如果我要把它里面的所有<换成a,那么就这样写:

x=replace(x,"<","a")

把data.aspx页面中的页面代码删除掉,只剩下头一句。

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="data.aspx.cs" Inherits="_Data" %>

Response.Clear()//清空缓冲区输出内容

Response.Write("输出字符串")//向客户端输出字符串

public static string NoHtml(string text)

{

//删除脚本

text = Regex.Replace(text, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase)

//删除HTML

text = Regex.Replace(text, @"<(.[^>]*)>", "", RegexOptions.IgnoreCase)

text = Regex.Replace(text, @"([\r\n])[\s]+", "", RegexOptions.IgnoreCase)

text = Regex.Replace(text, @"-->", "", RegexOptions.IgnoreCase)

text = Regex.Replace(text, @"<!--.*", "", RegexOptions.IgnoreCase)

text = Regex.Replace(text, @"&(quot|#34)", "\"", RegexOptions.IgnoreCase)

text = Regex.Replace(text, @"&(amp|#38)", "&", RegexOptions.IgnoreCase)

text = Regex.Replace(text, @"&(lt|#60)", "<", RegexOptions.IgnoreCase)

text = Regex.Replace(text, @"&(gt|#62)", ">", RegexOptions.IgnoreCase)

text = Regex.Replace(text, @"&(nbsp|#160)", " ", RegexOptions.IgnoreCase)

text = Regex.Replace(text, @"&(iexcl|#161)", "\xa1", RegexOptions.IgnoreCase)

text = Regex.Replace(text, @"&(cent|#162)", "\xa2", RegexOptions.IgnoreCase)

text = Regex.Replace(text, @"&(pound|#163)", "\xa3", RegexOptions.IgnoreCase)

text = Regex.Replace(text, @"&(copy|#169)", "\xa9", RegexOptions.IgnoreCase)

text = Regex.Replace(text, @"(\d+)", "", RegexOptions.IgnoreCase)

text.Replace("<", "")

text.Replace(">", "")

text.Replace("\r\n", "")

text = HttpContext.Current.Server.HtmlEncode(text).Trim()

return text

}


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5901596.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-07
下一篇 2023-03-07

发表评论

登录后才能评论

评论列表(0条)

保存