告別漏水困擾,改善住宅環境!細心防水團隊
30年經驗,各大企業、豪宅指定合作
輕鬆接案網提供氣泡紙、紙箱、打包技巧
讓您輕鬆搬家、沒有缺失與遺憾

首頁  •  j2h 論壇 • 程式設計討論     • 

[php] PHP正則表達式 過濾html

房東:張先生
發表時間:2012-10-24


 $contents = preg_replace("/\s+/", " ", $contents); //過濾多餘回車

    $contents=preg_replace("/<[ ]+/si","<",$contents); //過濾<__("<"號後面帶空格) 

$contents=preg_replace("/<\!--.*?-->/si","",$contents); //註釋   

$contents=preg_replace("/<(\!.*?)>/si","",$contents); //過濾DOCTYPE   

$contents=preg_replace("/<(\/?html.*?)>/si","",$contents); //過濾html標籤   

$contents=preg_replace("/<(\/?meta.*?)>/si","",$contents); //過濾meta標籤    

$contents=preg_replace("/<(\/?body.*?)>/si","",$contents); //過濾body標籤   

$contents=preg_replace("/<(\/?link.*?)>/si","",$contents); //過濾link標籤   

$contents=preg_replace("/<(\/?form.*?)>/si","",$contents); //過濾form標籤 

$contents=preg_replace("/cookie/si","COOKIE",$contents); //過濾COOKIE標籤   

$contents=preg_replace("/<(applet.*?)>(.*?)<(\/applet.*?)>/si","",$contents); //過濾applet標籤   

$contents=preg_replace("/<(\/?applet.*?)>/si","",$contents); //過濾applet標籤 

$contents=preg_replace("/<(style.*?)>(.*?)<(\/style.*?)>/si","",$contents); //過濾style標籤   

$contents=preg_replace("/<(\/?style.*?)>/si","",$contents); //過濾style標籤  

$contents=preg_replace("/<(title.*?)>(.*?)<(\/title.*?)>/si","",$contents); //過濾title標籤   

$contents=preg_replace("/<(\/?title.*?)>/si","",$contents); //過濾title標籤  

$contents=preg_replace("/<(object.*?)>(.*?)<(\/object.*?)>/si","",$contents); //過濾object標籤   

$contents=preg_replace("/<(\/?objec.*?)>/si","",$contents); //過濾object標籤     

$contents=preg_replace("/<(noframes.*?)>(.*?)<(\/noframes.*?)>/si","",$contents); //過濾noframes標籤   

$contents=preg_replace("/<(\/?noframes.*?)>/si","",$contents); //過濾noframes標籤   

$contents=preg_replace("/<(i?frame.*?)>(.*?)<(\/i?frame.*?)>/si","",$contents); //過濾frame標籤   

$contents=preg_replace("/<(\/?i?frame.*?)>/si","",$contents); //過濾frame標籤   

$contents=preg_replace("/<(script.*?)>(.*?)<(\/script.*?)>/si","",$contents); //過濾script標籤   

$contents=preg_replace("/<(\/?script.*?)>/si","",$contents); //過濾script標籤   

$contents=preg_replace("/javascript/si","Javascript",$contents); //過濾script標籤   

$contents=preg_replace("/vbscript/si","Vbscript",$contents); //過濾script標籤   

$contents=preg_replace("/on([az]+)\s*=/si","On\\1=",$contents); //過濾script標籤   

$contents=preg_replace("/&#/si","&#",$contents); //過濾script標籤,如javAsCript:alert('aabb)   

$contents=preg_replace("/<(\/?table.*?)>/si","",$contents); //過濾table標籤  

$contents=preg_replace("/<(\/?tr.*?)>/si","",$contents); //過濾tr標籤  

$contents=preg_replace("/<(\/?tbody.*?)>/si","",$contents); //過濾tbody標籤  

$contents=preg_replace("/<(\/?td.*?)>/si",",",$contents); //過濾td標籤 


$contents=preg_replace("/<(\/?img.*?)>/si","",$contents); //過濾img標籤  

$contents=preg_replace("/<(\/?input.*?)>/si","",$contents); //過濾input標籤  


$contents=preg_replace("/<(\/?font.*?)>/si","",$contents); //過濾font標籤

$contents=preg_replace("/<(\/?th.*?)>/si","",$contents); //過濾th標籤


$contents=preg_replace("/<(head.*?)>(.*?)<(\/head.*?)>/si","",$contents); //過濾head標籤  


$contents=preg_replace("/<(select.*?)>(.*?)<(\/select.*?)>/si","",$contents); //過濾select標籤   


$contents=preg_replace("/<(strong.*?)>(.*?)<(\/strong.*?)>/si","",$contents); //過濾strong標籤  


$contents=preg_replace("/<(label.*?)>(.*?)<(\/label.*?)>/si","",$contents); //過濾label標籤   


$contents=preg_replace("/<(a.*?)>(.*?)<(\/a.*?)>/si","",$contents); //過濾a標籤   





  • 贊助網站       

    廣利不動產-板橋在地生根最實在--新板特區指名度最高、值得您信賴的好房仲
    完整房訊,房屋、店面熱門精選物件,廣利不動產 優質仲介,房屋租賃、買賣資訊透明,交易真安心!
    廣利不動產-新板特區指名度最高、值得您信賴的好房仲
    您的托付,廣利用心為您服務

  • 1 樓住戶:jack
    發表時間:2012-10-24

    <?
    $str = "abc <我是誰 > ghi (正則表示式) fffjkl[你是誰] <mm> < opq <rst> uv";//原文
    $pattern = "/<[^>^<]*>/";// 正則表示式格式用於比對
    $replacement = ""; // 以此(空)字串來取代 (即刪除)
    $newStr = preg_replace($pattern, $replacement, $str);
    echo $newStr;

    ?>

    2 樓住戶:jeff
    發表時間:2012-10-26

    移除[ ] 主題



    <?


    $str='[分享] 好租好賣最優值';
    $str2='[問題] 誠心指教!';
    $str3='[討論]地產會泡沫化?';


    echo preg_replace('/\[[^\]]+\]/','',$str);

    echo preg_replace('/\[[^\]]+\]/','',$str2);

    echo preg_replace('/\[[^\]]+\]/','',$str3);

    ?>

    3 樓住戶:creakj
    發表時間:2012-11-02


    移除[] or () 後面文字

    $str1 = '打工20歲(40p)回復 1# Soldie';
    $str2 = '新竹加油站[30P]........回復 1# g'

    echo substr($str1, 0, strrpos($str1, ')') + 1);
    echo substr($str2, 0, strrpos($str2, ']') + 1);



     共 3 人回應  選擇頁數 【第1 頁】 

    姓名:
    佈告內容:
    其他選項: