导航:首页 > 净水问答 > 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相关的资料

热点内容
印染废水中cod排放量是多少 浏览:245
冷干机的滤芯如何拆下来 浏览:552
海尔净水器出水管接口怎么拆 浏览:13
河北水垢漏斗 浏览:689
白云区农村ppp污水项目 浏览:498
安吉尔水壶滤芯怎么拆 浏览:318
电厂化学废水调整及注意事项 浏览:892
什么叫纳米微晶技术净化器 浏览:43
百佳境界净水器如何 浏览:695
甲醇蒸馏塔再沸器的原理 浏览:268
ro膜氯化 浏览:984
洁厕灵能除垢 浏览:459
油烟机净化器的价格多少钱一台 浏览:334
净化器电源怎么测量 浏览:332
wq污水提升泵 浏览:415
污水处理50户需多少立方池 浏览:656
树脂是不是ab胶 浏览:694
减压蒸馏怎么拆 浏览:544
饮水机为什么加热一会就保温 浏览:287
电解法处理污水基于什么原理 浏览:229