① php怎麼過濾掉html啊,比如「[color=#111111]都說」
你可以看下這個函數是不是符合你的要求: strip_tags()
這個函數的作用是去除字元串中的html標簽, 只留下內容.
② C# 通過正則表達式進行html過濾 只留文字,圖片,<p>,<br>
|請參照以下代碼:
public static string FilterHtmlTag(string s)
{
//<...>標記正則表達式
return Regex.Replace(s, @"<[^>]*>", delegate(Match match)
{
string v = match.ToString();
//圖片,<p>,<br>正則表達式
Regex rx = new Regex(@"^<(p|內br|img.*)>$",
RegexOptions.Compiled | RegexOptions.IgnoreCase); //
if (rx.IsMatch(v))
{
return v; //保留圖容片,<p>,<br>
}
else
{
return ""; //過濾掉
}
});
}
③ php文件輸出如何過濾掉html,代碼如下
<b>asasasas</b>這個html標簽是加粗標簽,如果你想在瀏覽器上顯示的是版加粗的asasasas就直接輸出
<?php
echo "<b>asasasas</b>";
?>
如果你想輸權出的<b>asasasas</b>這個字元串的話呢
<?php
echo htmlspecialchars("<b>asasasas</b>");
?>
④ 我有一個頁面a.html,把它裡面的內容讀取到b.text中,我如何過濾掉<html></html>和<body></body>呢
String data="";
BufferedReader br;
BufferedWriter bw;
StringBuffer sb=new StringBuffer();
try {
br = new BufferedReader(new InputStreamReader(new FileInputStream(path+"\\"+"a.html")));
while((data = br.readLine())!=null){
String str=data.replaceAll("[<body><html>]", "");//這里是把<body><html>的標簽都替換為空
sb.append(str);
if(!str.equals("")||str.length()>0)
sb.append("\r\n"); //這里是如果字元串的長度大於0或者不等於空就換行
}
bw=new BufferedWriter(new FileWriter(new File(path+"\\"+"a.txt");
bw.write(sb.toString());//將讀出來的內容寫入a.txt文件
bw.flush();
bw.close();
}
} catch (Exception e) {
e.printStackTrace();
}
⑤ 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
⑥ java 如何過濾html代碼,只保留中文或英文及基本常用符號
很容易,首先建立一個字元串數組,也就是你需要過濾掉的html標簽String[] filterArrays = new String[]{"<html>","</html>","<table>","</table>".....一系列內有關html標簽的東西}
當你得到一容個html代碼的字元串時你可以循環遍歷上面的數組,然後調用String自帶的方法replaceAll();
我給你簡單的示範一下啊
String str = "dfgdgdfgdgd";//需要過濾的帶有HTML標簽的代碼字元串
for(int i=0;i<filterArrays.length;i++){
if(str.indexOf(filterArrays[i])!=0){
str = str.replaceAll(filterArrays[i],"");//將html標簽替換成了空格
}
}
這樣就搞定了,主要是你需要在filterArrays中增加你需要過濾的字元串,當然還會有更好的辦法,可以不用增加這樣的數組,因為出現"<"必然會有">",或者"/>"這樣的標簽,但是這樣做可能會將一些無關的也過濾掉了,總之兩種方法都可以,第一種呢我都給你寫了例子!祝你成功啊
⑦ jQuery 過濾html標簽屬性的特殊字元
您好,如果在表單中需要提交一字元串,其中包含,< > " &字元時,當我們把這字元串顯示到jsp頁面時,會和html標簽產生沖突,導致web頁面的某些部分消失或者格式不正確。為了解決以上問題,需要在顯示之前,對字元串進行代碼過濾。
把字元串中的 < 替換為 &It;
> 替換為 >
" 替換為 "
& 替換為 &
這里給出一個靜態的過濾代碼,供大家參考:
public class StringUtils {
/**
* This method takes a string which may contain HTML tags (ie, <b>,
* <table>, etc) and converts the '<'' and '>' characters to their HTML escape sequences.
* @param input the text to be converted.
* @return the input string with the characters '<' and '>' replaced with their HTML escape sequences.
*/
public static final String escapeHTMLTags(String input) {
//Check if the string is null or zero length -- if so, return
//what was sent in.
if (input == null || input.length() == 0) {
return input;
}
//Use a StringBuffer in lieu of String concatenation -- it is
//much more efficient this way.
StringBuffer buf = new StringBuffer(input.length());
char ch = ' ';
for (int i = 0; i < input.length(); i++) {
ch = input.charAt(i);
if (ch == '<') {
buf.append("<");
}
else if (ch == '>') {
buf.append(">");
}else if(ch == '"'){
buf.append(""");
}else if(ch == '&'){
buf.append("&");
}
else {
buf.append(ch);
}
}
return buf.toString();
}
}
此時,只需在jsp中對字元串調用此方法(StringUtils.escapeHTMLTags(str))即可。
⑧ mysql進行全文搜索的時候怎麼過濾html標簽
select text from table
where match(text) against('+php100 +論壇')
⑨ php 過濾掉html標簽及標簽內的所有內容
方法一:使用strip_tags()函數
strip_tags() 函數剝去字元串中的 HTML、XML 以及PHP的標簽。
使用內案例:
$string = "<p>這里是容潘旭博客</p>"
$newStr = strip_tags($string);
echo $newStr;
方法二:使用str_replace()函數
str_replace() 函數以其他字元替換字元串中的一些字元(區分大小寫)
使用案例:
$string = "<p>這里是潘旭博客</p>";
$newStr = str_replace(array("<p>","</p>"),array("",""));
echo $newStr;
另外還有一種是通過正則的方法,請參考:https://panxu.net/article/8385.html