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

熱點內容
換空調濾芯多少錢換一個 瀏覽:537
凈化器排水怎麼安裝 瀏覽:211
小踏板摩托車的機油濾芯在哪裡 瀏覽:269
深圳市污水管網建設 瀏覽:525
關於清理污水溝的創衛信息 瀏覽:21
什麼牌子凈水器和安利的差不多 瀏覽:590
污水處理費物價局 瀏覽:523
青川本地污水處理設備多少錢 瀏覽:997
從山東回武漢用隔離嗎 瀏覽:368
愛惠浦凈水器是哪個國家的產品 瀏覽:993
污水處理bod與cod怎麼降低 瀏覽:856
從上海回哈爾濱用隔離嗎 瀏覽:794
海水缸可以用瀑布過濾么 瀏覽:240
凈水器有機油味是怎麼回事 瀏覽:777
污水出水口水渾怎麼辦 瀏覽:145
美國反滲透膜怎麼樣 瀏覽:379
光敏樹脂dl 瀏覽:204
桑夏凈水機濾芯在什麼地方買 瀏覽:42
污水生化什麼意思 瀏覽:86
泌園凈水器純水口不出水怎麼辦 瀏覽:389