我在编辑内空时用FCKeditor文本编辑器把内空插入到数据库,我现在想把数据从数据库里读出来,在页面进行绑定数据时只显示文字并截取字符串该怎么做,求代码
解决方案 »
- Hibernate 可以操作MongoDB不?
- http://www.021com.com/(S(tyjbbarm4prlqa551zrsapi4))/web/DownloadIndex.aspx
- html控件select的赋值问题
- 如果在Visual.net中进行多会话调试?
- 哪个asp.net的blog比较好用?
- 各位老大,帮忙啊!!!关于msgbox!
- 关于控件的使用问题!!
- asp.net如何POST表单发送数据,并在提交按钮按下后再执行?
- INSERT INTO 语句的语法错误?
- 如何在datagrid中对某一行进行上移或下移,datagrid用datatable进行绑定
- 输入框中含有Html标签时页面报错
- webservice(asp.net c#开发)的地址后缀竟然是aspx,请教!
{ //删除脚本
Htmlstring = Regex.Replace(Htmlstring, @"<script(\s[^>]*?)?>[\s\S]*?</script>", "", RegexOptions.IgnoreCase);
//删除样式
Htmlstring = Regex.Replace(Htmlstring, @"<style>[\s\S]*?</style>", "", RegexOptions.IgnoreCase);
//删除html标签
Htmlstring = Regex.Replace(Htmlstring, @"<(.[^>]*)>", "", RegexOptions.IgnoreCase);
return Htmlstring; }
我一般用这个
比如 < , 转义成 < 存到数据库,读取的时候, < 就会自动转义成 < 了.
/// <summary>
/// HTML标签过滤
/// </summary>
/// <param name="strHtml">需要过滤的字符串</param>
/// <returns></returns>
public static string StripHTML(string strHtml)
{
string[] aryReg ={
@"<script[^>]*?>.*?</script>", @"<(\/\s*)?!?((\w+:)?\w+)(\w+(\s*=?\s*(([""'])(\\[""'tbnr]|[^\7])*?\7|\w+)|.{0})|\s)*?(\/\s*)?>",
@"([\r\n])[\s]+",
@"&(quot|#34);",
@"&(amp|#38);",
@"&(lt|#60);",
@"&(gt|#62);",
@"&(nbsp|#160);",
@"&(iexcl|#161);",
@"&(cent|#162);",
@"&(pound|#163);",
@"&(copy|#169);",
@"&#(\d+);",
@"-->",
@"<!--.*\n"
}; string[] aryRep = {
"",
"",
"",
"\"",
"&",
"<",
">",
" ",
"\xa1",//chr(161),
"\xa2",//chr(162),
"\xa3",//chr(163),
"\xa9",//chr(169),
"",
"\r\n",
""
}; string newReg = aryReg[0];
string strOutput = strHtml;
for (int i = 0; i < aryReg.Length; i++)
{
System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(aryReg[i], System.Text.RegularExpressions.RegexOptions.IgnoreCase);
strOutput = regex.Replace(strOutput, aryRep[i]);
}
strOutput.Replace("<", "");
strOutput.Replace(">", "");
strOutput = strOutput.Replace("\r\n", "");
return strOutput;
}