导航:首页 > 净水问答 > 怎么过滤html中的文字

怎么过滤html中的文字

发布时间:2023-11-15 06:03:00

① 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

阅读全文

与怎么过滤html中的文字相关的资料

热点内容
厨房净水器龙头怎么弄水 浏览:621
格力净水机滤芯叫什么名字 浏览:651
复氢水净水器水杯多少钱 浏览:255
内蒙古新农村污水处理有哪些 浏览:343
小型豆腐废水处理方案 浏览:99
工业废水在线监测工艺 浏览:601
过滤装置图简单 浏览:49
污水处理助凝剂是什么 浏览:328
净化器出现999怎么回事 浏览:470
真空泵过滤棉 浏览:449
蒸馏水用于化工产品 浏览:995
比速m3空调滤芯怎么换 浏览:870
水垢难除垢 浏览:49
热得快怎么烧水不起水垢 浏览:224
反渗透净水机储气罐压力怎么放 浏览:914
汽车漆面除垢怎么做 浏览:709
污水消毒方式都有哪几种 浏览:110
净水机小鸭高压开关多少钱 浏览:146
大型餐饮的潲水处理流程 浏览:572
处理什么废水需要助凝剂 浏览:614