『壹』 asp.net c# 過濾 html編輯器內容
Asp.net中如何過濾html,js,css代碼
以下為引用的內容:
#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
『貳』 uEditor 如何過濾html標簽
你可以在數據保存的時候,通過你服務端語言來過濾;
或者再數據保存前,用js過濾之後再進行保存。
但既然選擇使用富文本編輯器,何必在資料庫中顯示不帶HTML標簽的內容?
『叄』 ueditor插入html代碼保存後,再次編輯文章時html代碼被過濾只顯示文本內容!
遇到問題多看官方文檔和官方API。
官方初始化參數文檔:http://fex..com/ueditor/#start-config
官方API文檔:http://ueditor..com/doc/
最簡單的解決方專法如下:
//如下寫屬法即可
varue=UE.getEditor("editor",{
initialContent:"${initParam}"
});
如果不能滿足要求,比如這樣的話,之前在文本中插入的圖片,在修改時會展示<img>標簽,可以用filterTxtRules選項解決。當然,一般沒人會把圖片也跟文本一起存入資料庫
『肆』 js對html代碼的過濾
<script type="text/javascript">
var word="正常內容onclick,onmouseover,正常內容,正常內容";
word=word.replace(/onclick/g,"");
word=word.replace(/onmouseover/g,"");
alert(word);
</script>
『伍』 我想將一個編輯器(eWebEditor)輸入的內容中有HTML標記過濾掉,只剩下純文章,請問有這樣的函數或代碼么
eWebEditor本身就有純文本標簽,可以選擇它粘貼文字,就是無Html標簽的文字。當然,如果你的內容里如果有其它需要包含Html標簽內容,最簡單的辦法就是打開開始-〉程序-〉附件-〉記事本,將doc文本粘貼到裡面,再全選復制,再粘貼到編輯器中就是不帶格式的純文本,不過應該也會有<p>標簽。
『陸』 php如何過濾編輯器的html標簽
選擇1.將特殊符號進行轉換,可以用htmlspecialchars把<變為「<」等
選擇2.用正則表達式替換,將標簽都刪除:
$content=preg_replace('/\<.+?\>/','',$content);
『柒』 C# 堆文本編輯器裡面的內容html標簽進行過濾,除了a標簽以外全部過濾
用正則表抄達式來襲做
引用 using System.Text.RegularExpressions;
Match result;
result = Regex.Match(文本, @"(?<value><a>.+?<\/a>)");
string getstring = string.Empty;
while (result.Success)
{
getstring += result.Groups["value"].Value;
result = result.NextMatch();
}
getstring就是內容了
『捌』 想過濾 html 在線編輯器中含有超鏈接的內容,然後提交到資料庫! 網站是Asp網站!這個過濾怎麼做
應該都是用正則表達式吧、
『玖』 asp.net 中怎麼把後台通過文本編輯器添加的內容過濾掉html字元,然後在前台顯示出來試過了網上寫的辦法
public static string NoCode(string str)
{
if (str == null || str.Length == 0) return "";
str = System.Text.RegularExpressions.Regex.Replace(str, @"\<(?<x>[^\>]*)\>", @"", RegexOptions.IgnoreCase);
str = System.Text.RegularExpressions.Regex.Replace(str, @"\[(?<x>[^\]]*)\]", @"", RegexOptions.IgnoreCase);
str = str.Replace("", " ");
str = str.Replace(">", ">");
str = str.Replace("<", "<");
str = str.Replace("\n", " ");
str = str.Replace("\r", "");
str = str.Replace("'", "");
return str;
}
用這個就可以全部過慮掉