怎么过滤html代码 要做个新闻系统,新闻列表里只显示新闻的标题,发布日期,和200字的缩略内容,我想把新闻缩略内容过滤掉里面的html代码,请问怎么处理?ps:后台添加内容用的事fckeditor 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 private string NoHTML(string Htmlstring) { Htmlstring = Regex.Replace(Htmlstring, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase); 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; } Regex.Replace(str,@"<[^> ]+>",""); fckeditor编辑的不就是html代码吗?你要怎么过滤呢?比如有<p></p>标记,你是要去掉中间所有的内容吗? 楼上的兄弟,只能这个办法吗? 另问下能不能在fckeditor编辑器里输入的时候就不用使用html格式? public static string HtmlDiscode(string theString) { theString = theString.Replace("<script>", ""); theString = theString.Replace("</script>", ""); theString = theString.Replace(">", ">"); theString = theString.Replace("<", "<"); theString = theString.Replace(" ", ""); theString = theString.Replace(" ", ""); theString = theString.Replace(" ", ""); theString = theString.Replace(""", "\""); theString = theString.Replace("'", "\'"); theString = theString.Replace("<br/> ", "\n"); return theString; } 想去掉<p>标记~ 还有其他字体颜色啊什么的标记 主要是想让缩略内容看起来整齐 一致 //替换掉html字符,只显示文字信息。 public string replaceHtmlCode (string Htmlstring) { Htmlstring = Htmlstring.Replace( " <br/> ", "\n "); Htmlstring = Htmlstring.Replace( " <br/> ", "\r\n "); Htmlstring =Htmlstring.Replace( "< ", " < "); Htmlstring = Htmlstring.Replace( "> ", "> "); Htmlstring = Htmlstring.Replace( "" ", "\ " ") ; Htmlstring =Htmlstring.Replace ( "nbsp; ", " "); Htmlstring =Htmlstring.Replace ( "& ", " "); 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 ", " "); //对字符串长度进行判断。然后依据长短进行截取 if (Htmlstring.Length < 100) {//如果长度小于100个字符 return Htmlstring; } else { Htmlstring = Htmlstring.Substring(0,100) + "... "; return Htmlstring; } } ----------------------------- 调用显示 <asp:DataList id= "dlist_newmovement " runat= "server " Width= "100% "> <ItemTemplate> <%# replaceHtmlCode(DataBinder.Eval(Container, "DataItem.News_Content ").ToString())%> </ItemTemplate> </asp:DataList> Regex.Replace(str,@"<[^> ]+>","");过滤所有html public static string Getsub(int count, string str) { if (str.Length > count) return str.Substring(0, count) + "..."; else return str; } 关于window.open() 时间转换的问题 javascript中的List泛型集合 ASP.NET Teechart 使用 如何删除图片 不同 的界面间如何传递内容 请问在asp.net中如何遍历页面中所有的控件 请教一个问题 请教有关web services返回xml文件解析的一点疑问 我要安装ASP。NET应如何安装,请详细写下 关于一个老掉牙的问题。 导出Excel的时候格式还是.aspx格式。求教
{
Htmlstring = Regex.Replace(Htmlstring, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase);
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;
}
{
theString = theString.Replace("<script>", "");
theString = theString.Replace("</script>", "");
theString = theString.Replace(">", ">");
theString = theString.Replace("<", "<");
theString = theString.Replace(" ", "");
theString = theString.Replace(" ", "");
theString = theString.Replace(" ", "");
theString = theString.Replace(""", "\"");
theString = theString.Replace("'", "\'");
theString = theString.Replace("<br/> ", "\n");
return theString;
}
想去掉<p>标记~ 还有其他字体颜色啊什么的标记 主要是想让缩略内容看起来整齐 一致
public string replaceHtmlCode (string Htmlstring)
{
Htmlstring = Htmlstring.Replace( " <br/> ", "\n ");
Htmlstring = Htmlstring.Replace( " <br/> ", "\r\n ");
Htmlstring =Htmlstring.Replace( "< ", " < ");
Htmlstring = Htmlstring.Replace( "> ", "> ");
Htmlstring = Htmlstring.Replace( "" ", "\ " ") ;
Htmlstring =Htmlstring.Replace ( "nbsp; ", " ");
Htmlstring =Htmlstring.Replace ( "& ", " ");
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 ", " "); //对字符串长度进行判断。然后依据长短进行截取
if (Htmlstring.Length < 100)
{//如果长度小于100个字符
return Htmlstring;
}
else
{
Htmlstring = Htmlstring.Substring(0,100) + "... ";
return Htmlstring;
}
}
-----------------------------
调用显示
<asp:DataList id= "dlist_newmovement " runat= "server " Width= "100% ">
<ItemTemplate>
<%# replaceHtmlCode(DataBinder.Eval(Container, "DataItem.News_Content ").ToString())%>
</ItemTemplate>
</asp:DataList>
过滤所有html
public static string Getsub(int count, string str)
{
if (str.Length > count)
return str.Substring(0, count) + "...";
else
return str;
}