導航:首頁 > 編程語言 > phppregreplace正則

phppregreplace正則

發布時間:2024-10-26 05:15:48

A. php正則表達來獲取html中的部分內容

1、幾種函數的簡單說明:

(1)preg_grep -- 返回與模式匹配的數組單元
preg_grep 返回一個input 數組中與給定的 pattern 模式相匹配的單元所組成的數組。

(2)preg_match -- 進行正則表達式匹配
說明:int preg_match ( string pattern, string subject [, array matches [, int flags]] )在 subject 字元串中搜索與 pattern 給出的正則表達式相匹配的內容。 返回值0或1。

(3)preg_replace -- 執行正則表達式的搜索和替換

(4)preg_split -- 用正則表達式分割字元串

2. 一般來說,如果用正則來獲取匹配內容,一般使用 preg_match/ preg_match_all 函數。

補充回答:

正則表達式如下:
'%<div class="wap2"><span>功能</span>(.*?)</div>%si'

以下是代碼,經測試,運行正常:

<?php
$str = '<div class="wap2"><span>功能</span>這裡面是要獲取的內容,不能確定什麼字元,可能是數字(123456…)字母(badn…),特殊浮等(o_O\(^o^)/…)</div>';
$pa = '%<div class="wap2"><span>功能</span>(.*?)</div>%si';
preg_match($pa,$str,$r);
echo $r[1];
?>

B. PHP的preg_replace 正則替換

preg_replace("/http:\/\//","",$message)

$message = preg_replace(array(
"/\[img\]\s*([^\[\<\r\n]+?)\s*\[\/img\]/ies",
"/\[img=(\d{1,4})[x|\,](\d{1,4})\]\s*([^\[\<\r\n]+?)\s*\[\/img\]/ies",
"/http:\/\//" //加的,,
), $allowimgcode ? array(
"bbcodeurl('\\1', '<img src=\"%s\" onload=\"thumbImg(this)\" alt=\"\" />')",
"bbcodeurl('\\3', '<img width=\"\\1\" height=\"\\2\" src=\"%s\" border=\"0\" alt=\"\" />')"
) : array(
"bbcodeurl('\\1', '<a href=\"%s\" target=\"_blank\">%s</a>')",
"bbcodeurl('\\3', '<a href=\"%s\" target=\"_blank\">%s</a>')"
), $message);

其實你也可以在它處理完後加preg_replace("/http:\/\//","",$message)這句.

C. php 去掉 「<--」 到 「-->」 之間的字元 用正則表達式

$str = preg_replace('/<--(.+?)-->/', '', $str);

D. 用php中的preg_match_all匹配網頁上div的一段代碼,正則表達式該怎麼寫

<?php
$str='<div id="aaa111" name="bbb-bb" class="ccccc ddd">這里是我需要的代碼</div>';
$str=preg_replace("/<div id=\"aaa(.*)\">(.*)<\\/div>/iU","$2",$str); //你要想的代碼
echo $str;
?>

E. php中的 preg_replace() 怎麼用 preg_replace_callback()表示

preg_replace 是正則替換,正則就是一個用通配符的表達式。要想知道怎麼用,首先要去學習下正則,如果你的基礎還可以,找個視頻聽一聽,半個小時就可以入門了。

閱讀全文

與phppregreplace正則相關的資料

熱點內容
程序員能力關鍵詞 瀏覽:615
plc編程高級視頻教程 瀏覽:610
java遞歸求n 瀏覽:84
python絕對路徑導入 瀏覽:126
nex5g加密 瀏覽:975
18的空島伺服器地址 瀏覽:86
程序員要學什麼硬體 瀏覽:666
股票漲跌源碼怎麼看 瀏覽:576
加密軟體做法 瀏覽:55
美國程序員有多少中國人 瀏覽:739
人民日報app里怎麼看新聞早班車 瀏覽:585
忘了app怎麼辦 瀏覽:529
如何用雲伺服器做雲平台 瀏覽:299
非箍筋加密區剪力 瀏覽:117
利聯科技伺服器卡怎麼辦 瀏覽:384
js和python哪個好 瀏覽:461
c盤的哪些文件夾沒用 瀏覽:81
文件為什麼會超出在線解壓限制 瀏覽:591
python類實例化對象 瀏覽:797
硬碟dos外部命令 瀏覽:794