1. 程式人生 > >php正則過濾html標籤、空格、換行

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(

相關推薦

php過濾html標籤空格

$str=preg_replace("/\s+/", " ", $str); //過濾多餘回車 $str=preg_replace("/<[]+/si","<",$str);//過濾<__("<"號後面帶空格) $str=preg_replace("/<\!--.*?-->

php 匹配html標籤

$html = ' <a id="01" name="xkmlChoose">哲學</a> <a id="02" name="xkmlChoose">經濟學</a>

通過過濾html標籤

publicstatic String delHtml(String inputString) {        String htmlStr = inputString; // 含html標籤的字串        String textStr ="";        java.util.regex.Patt

PHP 匹配 HTML 標籤

$str = '<div class="subnav-title-name"> <a href="http://www.autohome.com.cn/16/">一汽-大眾-捷

java+Jsoup 過濾html網頁標籤【多執行緒資料採集之二】

java採集資料,獲取了 html整個文字之後。  該考慮的是如何過濾掉html標籤, 得到自己所需要的重要資料了。 實現方法有多種辦法,第一:用正則,第二:用第三方jar包,其實本質也是封裝了正則表示式 今天就以 Jsoup 第三方jar包來講解。 現在貼上

Python3之清除html標籤

程式碼示例 impoort re def clear_html_re(content): ''' 正則清除HTML標籤 :param content:原文字 :return: 清除後的文字 ''' s_content = re.sub(

php提取html圖片(img)src地址與任意屬性的方法

<?php /*PHP正則提取圖片img標記中的任意屬性*/ $str  =  '<center><img src="/uploads/images/2017020716154162.jpg" height="120" width="120"

去除html標籤

正則匹配html標籤簡單的思路就是:匹配所有<>裡的不是>的字元。這樣就能保證匹配到的那些<...>裡面不會再有尖括號。 描述有點繞,看下程式碼: var reg = /<[^>]+>/ig; 解釋一下:^ 是非的意思,所以[

清除HTML標籤但保留其中一部分標籤

str="<a href=""a.htm"">a.htm</a><div>afefe</div>feaa<b>bbb</b> <a href=http://www.baidu.com id=""ggg"">ggg</a

php表示式替換標籤

1.strip_tags(剝去字串中的 HTML 標籤) strip_tags() 函式剝去字串中的 HTML、XML 以及 PHP 的標籤。 2.字串替換 str_replace(array(“ ”,”&nbsp;”,”\t”,”\r\n”,”\r”,”\n”

刪除HTML標籤

<[^>]*> 刪除所有HTML標籤 /^$/ 匹配空白行 <.*> 指令碼及指令碼包裹部分都被匹配(<p>hello</p>) *其他HTML正則匹配: http://blog.csdn.net/gzeehg007

php提取html圖片(img)src地址與任意屬性

簡單版:<?php header("Content-Type: text/html;charset=utf-8"); $str = '<div class="ui-block-a" align="center"> <a href="

php 過濾中英文標點

/**  * 過濾中英文標籤  */     public static function punctFilter($text){         $text=preg_replace("/[[:punct:]\s]/",' ',$text);         $text=u

PHP 匹配a標籤間的內容

$author=$forum['lastpost']['author']; //獲取a標籤字串 $match='/<a href="[^"]*"[^>]*>(.*)<\/a>/';//a標籤正則匹配 preg_match_all($match,$

php 去掉標籤空格 類似simple_html_dom.php的作用

function DeleteHtml(){ //清除空格和換行 $str = trim($str); //清除字串兩邊的空格 $str = strip_tags($str,""); //利用php自帶的函式清除html格式 $str = preg_replace("/\t/","",$str);

PHP中關於表示式匹配任意字元(包括符)的寫法

今天在想使用正則表示式來獲取一段文字中的任意字元。於是很隨意得就寫出如下匹配規則: (.*) 結 果執行之後才發現,無法獲得換行之後的文字。於是查了一下手冊,才發現正則表示式中,“.”(點符號)匹配的是除了換行符“/n”以外的所有字元。同時, 手冊上還有一句話:要匹配包括

表示式匹配任意字元(包括符)的寫法

今天在Java中想使用正則表示式來獲取一段文字中的任意字元。於是很隨意得就寫出如下匹配規則:  (.*)  結

php過濾html標籤表示式

<?php $str=preg_replace("/\s+/", " ", $str); //過濾多餘回車 $str=preg_replace("/<[ ]+/si","<",$str); //過濾<__("<"號後面帶空格) $str=pre

C# 表示式html匹配input標籤及匹配input的value及獲取aspnet頁面VIEWSTATEEVENTVALIDATION的UI狀態儲存值

1、使用正則表示式從html內容中獲取 input 標籤,然後從 input 標籤中獲取屬性值; 也可以使用正則表示式捕獲組獲取value,在2中說明 using System.Text.RegularExpressions; string excelHtml = divMX.Inne

表示式之過濾html標籤

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html