導航:首頁 > 凈水問答 > 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