在做项目的过程中,我们经常需要用到过滤一些html标签来实现提高数据的安全性,其实就是删除那些对应用程序有潜在危害的数据。它用于去除标签以及删除或编码不需要的字符。
首先分享一些比较常见的
<span style="color: #800080">$str</span>=<span style="color: #008080">preg_replace</span>("/<s>]*?srcs*=s*('|")(.*?)\1[^>]*?/?s*>/i","", <span style="color: #800080">$str</span><span style="color: #000000">); //过滤img标签 </span><span style="color: #800080">$str</span>=preg_replace("/s+/","", <span style="color: #800080">$str</span><span style="color: #000000">); //过滤多余回车 </span><span style="color: #800080">$str</span>=preg_replace("/$str); //过滤<__ style="color: #000000">号后面带空格) <span style="color: #800080">$str</span>=preg_replace("/<!--.*?-->/si","",<span style="color: #800080">$str</span><span style="color: #000000">); //注释 </span><span style="color: #800080">$str</span>=preg_replace("//si","",<span style="color: #800080">$str</span><span style="color: #000000">); //过滤DOCTYPE </span><span style="color: #800080">$str</span>=preg_replace("//si","",<span style="color: #800080">$str</span><span style="color: #000000">); //过滤html标签 </span><span style="color: #800080">$str</span>=preg_replace("//si","",<span style="color: #800080">$str</span><span style="color: #000000">); //过滤head标签 </span><span style="color: #800080">$str</span>=preg_replace("//si","",<span style="color: #800080">$str</span><span style="color: #000000">); //过滤meta标签 </span><span style="color: #800080">$str</span>=preg_replace("//si","",<span style="color: #800080">$str</span><span style="color: #000000">); //过滤body标签 </span><span style="color: #800080">$str</span>=preg_replace("//si","",<span style="color: #800080">$str</span><span style="color: #000000">); //过滤link标签 </span><span style="color: #800080">$str</span>=preg_replace("//si","",<span style="color: #800080">$str</span><span style="color: #000000">); //过滤form标签 </span><span style="color: #800080">$str</span>=preg_replace("/cookie/si","COOKIE",<span style="color: #800080">$str</span><span style="color: #000000">); //过滤COOKIE标签 // http://www.manongjc.com/article/1345.html </span><span style="color: #800080">$str</span>=preg_replace("/(.*?)/si","",<span style="color: #800080">$str</span><span style="color: #000000">); //过滤applet标签 </span><span style="color: #800080">$str</span>=preg_replace("//si","",<span style="color: #800080">$str</span><span style="color: #000000">); //过滤applet标签 </span><span style="color: #800080">$str</span>=preg_replace("/(.*?)/si","",<span style="color: #800080">$str</span><span style="color: #000000">); //过滤style标签 </span><span style="color: #800080">$str</span>=preg_replace("//si","",<span style="color: #800080">$str</span><span style="color: #000000">); //过滤style标签 </span><span style="color: #800080">$str</span>=preg_replace("/(.*?)/si","",<span style="color: #800080">$str</span><span style="color: #000000">); //过滤title标签 </span><span style="color: #800080">$str</span>=preg_replace("//si","",<span style="color: #800080">$str</span><span style="color: #000000">); //过滤title标签 </span><span style="color: #800080">$str</span>=preg_replace("/object.*?)>(.*?)object.*?)>/si","",<span style="color: #800080">$str</span><span style="color: #000000">); //过滤object标签 </span><span style="color: #800080">$str</span>=preg_replace("//si","",<span style="color: #800080">$str</span><span style="color: #000000">); //过滤object标签 </span><span style="color: #800080">$str</span>=preg_replace("/(.*?)/si","",<span style="color: #800080">$str</span><span style="color: #000000">); //过滤noframes标签 </span><span style="color: #800080">$str</span>=preg_replace("//si","",<span style="color: #800080">$str</span><span style="color: #000000">); //过滤noframes标签 </span><span style="color: #800080">$str</span>=preg_replace("/(.*?)/si","",<span style="color: #800080">$str</span><span style="color: #000000">); //过滤frame标签 </span><span style="color: #800080">$str</span>=preg_replace("//si","",<span style="color: #800080">$str</span><span style="color: #000000">); //过滤frame标签 </span><span style="color: #800080">$str</span>=preg_replace("/(.*?)/si","",<span style="color: #800080">$str</span><span style="color: #000000">); //过滤script标签 </span><span style="color: #800080">$str</span>=preg_replace("//si","",<span style="color: #800080">$str</span><span style="color: #000000">); //过滤script标签 </span><span style="color: #800080">$str</span>=preg_replace("/javascript/si","Javascript",<span style="color: #800080">$str</span><span style="color: #000000">); //过滤script标签 </span><span style="color: #800080">$str</span>=preg_replace("/vbscript/si","Vbscript",<span style="color: #800080">$str</span><span style="color: #000000">); //过滤script标签 </span><span style="color: #800080">$str</span>=preg_replace("/on([a-z]+)s*=/si","On\1=",<span style="color: #800080">$str</span><span style="color: #000000">); //过滤script标签 </span><span style="color: #800080">$str</span>=preg_replace("/&<span style="color: #008000">#</span><span style="color: #008000">/si","&#",$str); //过滤script标签 </span></__></s>
更简单些的写法:
<span style="color: #0000ff">function</span> delhtml(<span style="color: #800080">$str</span>){ <span style="color: #008000">//</span><span style="color: #008000">清除html标签 </span> <span style="color: #800080">$st</span>=-1; <span style="color: #008000">//</span><span style="color: #008000">开始 </span> <span style="color: #800080">$et</span>=-1; <span style="color: #008000">//</span><span style="color: #008000">结束 </span> <span style="color: #800080">$stmp</span>=<span style="color: #0000ff">array</span><span style="color: #000000">(); </span><span style="color: #800080">$stmp</span>[]=" "<span style="color: #000000">; </span><span style="color: #800080">$len</span>=<span style="color: #008080">strlen</span>(<span style="color: #800080">$str</span><span style="color: #000000">); </span><span style="color: #0000ff">for</span>(<span style="color: #800080">$i</span>=0;<span style="color: #800080">$i</span>$len;<span style="color: #800080">$i</span>++<span style="color: #000000">){ </span><span style="color: #800080">$ss</span>=<span style="color: #008080">substr</span>(<span style="color: #800080">$str</span>,<span style="color: #800080">$i</span>,1<span style="color: #000000">); </span><span style="color: #0000ff">if</span>(<span style="color: #008080">ord</span>(<span style="color: #800080">$ss</span>)==60){ <span style="color: #008000">//</span><span style="color: #008000">ord(" <span style="color: #800080">$st</span>=<span style="color: #800080">$i</span><span style="color: #000000">; } </span><span style="color: #0000ff">if</span>(<span style="color: #008080">ord</span>(<span style="color: #800080">$ss</span>)==62){ <span style="color: #008000">//</span><span style="color: #008000">ord(">")==62 </span> <span style="color: #800080">$et</span>=<span style="color: #800080">$i</span><span style="color: #000000">; </span><span style="color: #0000ff">if</span>(<span style="color: #800080">$st</span>!=-1<span style="color: #000000">){ </span><span style="color: #800080">$stmp</span>[]=<span style="color: #008080">substr</span>(<span style="color: #800080">$str</span>,<span style="color: #800080">$st</span>,<span style="color: #800080">$et</span>-<span style="color: #800080">$st</span>+1<span style="color: #000000">); } } } </span><span style="color: #800080">$str</span>=<span style="color: #008080">str_replace</span>(<span style="color: #800080">$stmp</span>,"",<span style="color: #800080">$str</span><span style="color: #000000">); </span><span style="color: #0000ff">return</span> <span style="color: #800080">$str</span><span style="color: #000000">; } </span></span>
再来一个:
<span style="color: #0000ff">function</span> clear_html_label(<span style="color: #800080">$html</span><span style="color: #000000">) { </span><span style="color: #800080">$search</span> = <span style="color: #0000ff">array</span> ("'<script>]*?>.*?</script>'si", "']*?>'si", "'([rn])[s]+'", "'&(quot|#34);'i", "'&(amp|#38);'i", "'&(lt|#60);'i", "'&(gt|#62);'i", "'&(nbsp|#160);'i", "'&(iexcl|#161);'i", "'&(cent|#162);'i", "'&(pound|#163);'i", "'&(copy|#169);'i", "'(d+);'e"<span style="color: #000000">); </span><span style="color: #800080">$replace</span> = <span style="color: #0000ff">array</span> ("", "", "1", """, "&", "", " ", chr(161), chr(162), chr(163), chr(169), "<span style="color: #008080">chr</span>(1)"<span style="color: #000000">); return preg_replace(</span><span style="color: #800080">$search</span>, <span style="color: #800080">$replace</span>, <span style="color: #800080">$html</span><span style="color: #000000">); } </span>

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

mPDF
mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),

MinGW - Minimalist GNU for Windows
這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。

SublimeText3 英文版
推薦:為Win版本,支援程式碼提示!

SecLists
SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。

SublimeText3漢化版
中文版,非常好用