導航:首頁 > 凈水問答 > 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相關的資料

熱點內容
不要排放廢水用英文怎麼講 瀏覽:147
網路污水渠 瀏覽:593
飲水機有啤酒味怎麼辦 瀏覽:825
石油後的污水 瀏覽:15
雪佛蘭汽濾芯卡子怎麼拆 瀏覽:673
XRV15T怎麼換空氣濾芯 瀏覽:404
污水系統操作說明書怎麼寫 瀏覽:829
崇州市污水排放怎麼樣 瀏覽:135
魚缸有了水垢怎麼辦 瀏覽:365
凈水壺底部出現綠色怎麼清洗 瀏覽:459
泌之源飲水機多少錢了 瀏覽:999
宜興高溫濾芯多少錢 瀏覽:337
聚乙烯樹脂回收多少錢一噸 瀏覽:481
從沈陽回白城用隔離嗎 瀏覽:642
過濾網清洗後能用吹風吹乾嗎 瀏覽:247
安徽煤油濾芯多少錢 瀏覽:311
地下室排污水管怎麼接 瀏覽:834
牙齒做納米樹脂貼面 瀏覽:510
日本福島每天的廢水 瀏覽:515
美的飛利浦凈水器怎麼樣 瀏覽:53