導航:首頁 > 編程語言 > 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正則相關的資料

熱點內容
無線路由如何設置成伺服器 瀏覽:136
QQ飛車源碼更新 瀏覽:897
虛擬機中編譯器 瀏覽:474
台達PLC編譯按鈕在哪裡 瀏覽:137
非編程計算器多少錢 瀏覽:653
房本還完貸款解壓 瀏覽:816
中國程序員有出名嗎 瀏覽:546
亳州雲伺服器 瀏覽:630
程序員最難的面試 瀏覽:892
配音秀app怎麼誦讀 瀏覽:751
sparkcore源碼 瀏覽:100
程序員中年生活 瀏覽:355
讀取加密信息失敗怎麼回事 瀏覽:510
編譯過程之後是預處理嗎 瀏覽:351
安卓是基於什麼做出來 瀏覽:600
視頻字幕提取APP怎麼使用 瀏覽:59
js通過ip地址連接伺服器嗎 瀏覽:848
java數字金額大寫金額 瀏覽:858
人人影視路由器固件編譯 瀏覽:967
照片通訊錄簡訊怎麼從安卓到蘋果 瀏覽:458