导航:首页 > 净水问答 > php过滤br

php过滤br

发布时间:2022-12-22 00:22:25

❶ php过滤非法字符

帮你写了个函数,要用时,调用一下就可以了,希望对你有帮组
function safe_string($str){ //过滤安全字符
$str=str_replace("'","",$str);
$str=str_replace('"',"",$str);
$str=str_replace(" ","$nbsp;",$str);
$str=str_replace("\n;","<br/>",$str);
$str=str_replace("<","<",$str);
$str=str_replace(">",">",$str);
$str=str_replace("\t"," ",$str);
$str=str_replace("\r","",$str);
$str=str_replace("/[\s\v]+/"," ",$str);
return $str;
}

❷ 求一个php简单的过滤除<br>,<p>,<style>html标签的正则或方法

针对你这个<a>123</a>的例子的

$a=<<<str
<a>123</a>
str;
$preg ="/<(a)>(.*?)<\/(\1)>/is";
$str = preg_replace($preg, "<a>\\2</a>", $a);
echo $str;

除此之外PHP还有一个 过滤标签的函内数 你可以看容一下手册

❸ php如何过滤编辑器的html标签

选择1.将特殊符号进行转换,可以用htmlspecialchars把<变为“<”等
选择2.用正则表达式替换,将标签都删除:
$content=preg_replace('/\<.+?\>/','',$content);

❹ 用php过滤html部分标签

$str=preg_replace("/\s+/", " ", $str); //过滤多余回车
$str=preg_replace("/<[ ]+/si","<",$str); //过滤<__("<"号后面带空格)

$str=preg_replace("/<\!--.*?-->/si","",$str); //注释
$str=preg_replace("/<(\!.*?)>/si","",$str); //过滤DOCTYPE
$str=preg_replace("/<(\/?html.*?)>/si","",$str); //过滤html标签
$str=preg_replace("/<(\/?head.*?)>/si","",$str); //过滤head标签
$str=preg_replace("/<(\/?meta.*?)>/si","",$str); //过滤meta标签
$str=preg_replace("/<(\/?body.*?)>/si","",$str); //过滤body标签
$str=preg_replace("/<(\/?link.*?)>/si","",$str); //过滤link标签
$str=preg_replace("/<(\/?form.*?)>/si","",$str); //过滤form标签
$str=preg_replace("/cookie/si","COOKIE",$str); //过滤COOKIE标签

$str=preg_replace("/<(applet.*?)>(.*?)<(\/applet.*?)>/si","",$str); //过滤applet标签
$str=preg_replace("/<(\/?applet.*?)>/si","",$str); //过滤applet标签

$str=preg_replace("/<(style.*?)>(.*?)<(\/style.*?)>/si","",$str); //过滤style标签
$str=preg_replace("/<(\/?style.*?)>/si","",$str); //过滤style标签

$str=preg_replace("/<(title.*?)>(.*?)<(\/title.*?)>/si","",$str); //过滤title标签
$str=preg_replace("/<(\/?title.*?)>/si","",$str); //过滤title标签

$str=preg_replace("/<(object.*?)>(.*?)<(\/object.*?)>/si","",$str); //过滤object标签
$str=preg_replace("/<(\/?objec.*?)>/si","",$str); //过滤object标签

$str=preg_replace("/<(noframes.*?)>(.*?)<(\/noframes.*?)>/si","",$str); //过滤noframes标签
$str=preg_replace("/<(\/?noframes.*?)>/si","",$str); //过滤noframes标签

$str=preg_replace("/<(i?frame.*?)>(.*?)<(\/i?frame.*?)>/si","",$str); //过滤frame标签
$str=preg_replace("/<(\/?i?frame.*?)>/si","",$str); //过滤frame标签

$str=preg_replace("/<(script.*?)>(.*?)<(\/script.*?)>/si","",$str); //过滤script标签
$str=preg_replace("/<(\/?script.*?)>/si","",$str); //过滤script标签
$str=preg_replace("/javascript/si","Javascript",$str); //过滤script标签
$str=preg_replace("/vbscript/si","Vbscript",$str); //过滤script标签
$str=preg_replace("/on([a-z]+)\s*=/si","On\\1=",$str); //过滤script标签
$str=preg_replace("/&#/si","&#",$str); //过滤script标签,如javAsCript:alert(

清除空格,换行

function DeleteHtml($str)
{
$str = trim($str);
$str = strip_tags($str,"");
$str = ereg_replace("\t","",$str);
$str = ereg_replace("\r\n","",$str);
$str = ereg_replace("\r","",$str);
$str = ereg_replace("\n","",$str);
$str = ereg_replace(" "," ",$str);
return trim($str);
}

过滤HTML属性

1,过滤所有html标签的正则表达式:

复制代码 代码如下:

</?[^>]+>

//过滤所有html标签的属性的正则表达式:

$html = preg_replace("/<([a-zA-Z]+)[^>]*>/","<\\1>",$html);

3,过滤部分html标签的正则表达式的排除式(比如排除<p>,即不过滤<p>):

复制代码 代码如下:

</?[^pP/>]+>

4,过滤部分html标签的正则表达式的枚举式(比如需要过滤<a><p><b>等):

复制代码 代码如下:

</?[aApPbB][^>]*>

5,过滤部分html标签的属性的正则表达式的排除式(比如排除alt属性,即不过滤alt属性):

复制代码 代码如下:

\s(?!alt)[a-zA-Z]+=[^\s]*

6,过滤部分html标签的属性的正则表达式的枚举式(比如alt属性):

复制代码 代码如下:

(\s)alt=[^\s]*

❺ 用PHP如何过滤空格

1、头尾来过滤空格 trim

代码:自

<html>
<body>
<?php
$str="HelloWorld!";
echo"Withouttrim:".$str;
echo"<br/>";
echo"Withtrim:".trim($str);
?>
<body>
<html>

输出结果:

Withouttrim:HelloWorld!
Withtrim:HelloWorld!


2、内容中的空格

str_replace(" ","","$array");
str_replace(find,replace,string,count)
参数 描述
find 必需。规定要查找的值。
replace 必需。规定替换 find 中的值的值。
string 必需。规定被搜索的字符串。
count 可选。一个变量,对替换数进行计数。

❻ php怎样用正则表达式提取span标签中内容并过滤掉p和br标签

  1. 你要过滤的字符串是不是就都是这种,就这么长的。

  2. 你的需求是不是就是把字符串里面的内各种容标签都去掉?

如果你的需求和上面的说的相符,不需要用正则表达式,PHP 提供了 strip_tags 函数,用来过滤字符串里面的 html 标签,接收两个参数:第一个参数是要处理的字符串,第二个参数是允许(要保留)的tag

$str='<spanid="aaa"><p>11111</p><br><p>22222</p><span>';

echostrip_tags($str);//output:1111122222

echostrip_tags($str,'<span>');//output:<spanid="aaa">1111122222<span>

我觉得这可能是你的实际需求,如果不符合你的需求,继续追问。

阅读全文

与php过滤br相关的资料

热点内容
布谷400G换滤芯怎么复位 浏览:884
污水生化膜用什么保养 浏览:261
污水泵四根线怎么接七根线 浏览:7
华宁县污水处理厂建设工程 浏览:24
型不饱和树脂 浏览:792
饮水机水烧开后为什么会断电 浏览:39
纯水机上的盖子是什么意思 浏览:27
1元纯净水是多少升 浏览:807
卫生所污水中检出放射性是什么 浏览:547
超纯水氮气一小时用多少 浏览:488
住宅楼有污水怎么处理 浏览:701
一般净水机水芯多少钱一个 浏览:846
BWT前置过滤器怎么换滤芯 浏览:545
南安净化器多少钱 浏览:732
过滤厨房龙头安装示意图 浏览:874
保定一桶纯净水多少钱 浏览:96
污水池空间怎么清理 浏览:439
净水机废水比什么原理 浏览:686
or反渗透膜8040 浏览:904
风景区污水直排怎么处罚 浏览:767