導航:首頁 > 編程語言 > php過濾a標簽

php過濾a標簽

發布時間:2022-05-04 03:47:19

㈠ 用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 正則過濾掉 指定的a標簽

我這個更好
<?php
$str='<a class="qc" href="/car">汽車</a><a class="db" href="/car">大巴</a><a class="qc" href="/car">汽車</a>';
$str=preg_replace("/<a class=\"qc\" href=\"(.*)\">(.*)<\\/a>/iU","$2",$str); //過濾script標簽
echo $str;
?>

㈢ php正則匹配所有a標簽,並刪除

1,過濾所有html標簽的正則表達式:</?[^>]+>
2,過濾所有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]*

㈣ php怎麼過濾

使用單獨一個模塊,這個模塊負責所有的安全處理。

這個模塊被包含在所有公開的 PHP 腳本的最前端(或者非常靠前的部分)。

參考下面的腳本security.inc

<?php
switch($_POST['form'])
{
case'login':
$allowed=array();
$allowed[]='form';
$allowed[]='username';
$allowed[]='password';
$sent=array_keys($_POST);
if($allowed==$sent)
{
include'/inc/logic/process.inc';
}
break;
}
?>

㈤ php 過濾掉html標簽及標簽內的所有內容

方法一:使用strip_tags()函數
strip_tags() 函數剝去字元串中的 HTML、XML 以及PHP的標簽。
使用案例:
$string = "<p>這里是潘旭博客</p>"
$newStr = strip_tags($string);
echo $newStr;

方法二:使用str_replace()函數
str_replace() 函數以其他字元替換字元串中的一些字元(區分大小寫)
使用案例:
$string = "<p>這里是潘旭博客</p>";
$newStr = str_replace(array("<p>","</p>"),array("",""));
echo $newStr;

另外還有一種是通過正則的方法,請參考:https://panxu.net/article/8385.html

㈥ php正則表達式去除A標簽求解答

不用去, 你是不是不想讓 這段html解析?

很簡單 , 你這么寫就行:

$str = htmlspecialchars('<a href="www..com" target="_blank" class="keylink">玉石</a>');

echo $str;

你看看最終的$str 是不是不會被解析了, 原理的話你查看下網頁源碼你就一目瞭然了.

㈦ php 用正則表達式,去除A標簽

stringstrip_tags ( string$str [, string$allowable_tags ] )
從字元串中去除 HTML 和 PHP 標記

㈧ php正則表達式去掉開頭的a標簽

$res = preg_replace("/<a.+<\/a>(.*)/", "$1", $a);

$res就是你要的結果

㈨ php 正則 匹配所有有a標簽的一段文字 全部去除

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class test
{
public static void main(String[] args) throws IOException
{
System.out.print("輸入圓盤的個數:");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str=br.readLine();
int m=Integer.parseInt(str);
System.out.println("移動步驟:");
hanoi(m,'A','B','C');
}

㈩ PHP過濾html,把html代碼中的a標簽的target屬性由_blank改為 _self ,如何才能實現

$string 整個頁面的代碼
str_replace("_blank","_self ",$string)

閱讀全文

與php過濾a標簽相關的資料

熱點內容
如何壓縮文件夾聯想電腦 瀏覽:583
程序員的學習之旅 瀏覽:440
apkdb反編譯 瀏覽:922
雪花演算法為什麼要二進制 瀏覽:825
在文檔中打開命令行工具 瀏覽:608
android圖標尺寸規范 瀏覽:369
python實用工具 瀏覽:208
流量計pdf 瀏覽:936
科東加密認證價格 瀏覽:532
dos命令讀文件 瀏覽:996
成為程序員需要什麼學歷 瀏覽:672
pdf農葯 瀏覽:228
canal加密 瀏覽:497
日本安卓系統和中國有什麼區別 瀏覽:137
linux命令行修改文件 瀏覽:838
從編譯和解釋的角度看 瀏覽:649
徐志摩pdf 瀏覽:651
夏天解壓球視頻 瀏覽:304
全封閉壓縮機qd91h 瀏覽:668
如何在我的世界免費開一個伺服器 瀏覽:329