以下是引用片段: 以下为引用的内容: #region/// 过滤html,js,css代码 /// <summary> /// 过滤html,js,css代码 /// </summary> /// <param name="html">参数传入</param> /// <returns></returns> public static string checkstr(string html) { system.text.regularexpressions.regex regex1 = new system.text.regularexpressions.regex(@"<script[/s/s]+</script *>", system.text.regularexpressions.regexoptions.ignorecase); system.text.regularexpressions.regex regex2 = new system.text.regularexpressions.regex(@" href *= *[/s/s]*script *:", system.text.regularexpressions.regexoptions.ignorecase); system.text.regularexpressions.regex regex3 = new system.text.regularexpressions.regex(@" no[/s/s]*=", system.text.regularexpressions.regexoptions.ignorecase); system.text.regularexpressions.regex regex4 = new system.text.regularexpressions.regex(@"<iframe[/s/s]+</iframe *>", system.text.regularexpressions.regexoptions.ignorecase); system.text.regularexpressions.regex regex5 = new system.text.regularexpressions.regex(@"<frameset[/s/s]+</frameset *>", system.text.regularexpressions.regexoptions.ignorecase); system.text.regularexpressions.regex regex6 = new system.text.regularexpressions.regex(@"/<img[^/>]+/>", system.text.regularexpressions.regexoptions.ignorecase); system.text.regularexpressions.regex regex7 = new system.text.regularexpressions.regex(@"</p>", system.text.regularexpressions.regexoptions.ignorecase); system.text.regularexpressions.regex regex8 = new system.text.regularexpressions.regex(@"<p>", system.text.regularexpressions.regexoptions.ignorecase); system.text.regularexpressions.regex regex9 = new system.text.regularexpressions.regex(@"<[^>]*>", system.text.regularexpressions.regexoptions.ignorecase); html = regex1.replace(html, ""); //过滤<script></script>标记 html = regex2.replace(html, ""); //过滤href=javascript: (<a>) 属性 html = regex3.replace(html, " _disibledevent="); //过滤其它控件的on...事件 html = regex4.replace(html, ""); //过滤iframe html = regex5.replace(html, ""); //过滤frameset html = regex6.replace(html, ""); //过滤frameset html = regex7.replace(html, ""); //过滤frameset html = regex8.replace(html, ""); //过滤frameset html = regex9.replace(html, ""); html = html.replace(" ", ""); html = html.replace("</strong>", ""); html = html.replace("<strong>", ""); return html; } #endregion #region /// 过滤p /p代码 /// <summary> /// 过滤p /p代码 /// </summary> /// <param name="html">参数传入</param> /// <returns></returns> public static string inputstr(string html) { html = html.replace(@"/<img[^/>]+/>", ""); html = html.replace(@"<p>", ""); html = html.replace(@"</p>", ""); return html; } #endregion /// <summary> /// 截取字符串 /// </summary> /// <param name="str"></param> /// <param name="length"></param> /// <returns></returns> protected string getlength(string str, int length) { string strr = str; if (str.length > length) { strr = str.substring(0, length) + "..."; } return strr; } |
新闻热点
疑难解答