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

熱點內容
javatomcat圖片 瀏覽:413
程序員生產智能創意 瀏覽:65
匯和銀行app怎麼登錄 瀏覽:381
騰訊伺服器如何上傳源碼 瀏覽:739
單片機的原理概述 瀏覽:508
火控pdf 瀏覽:267
如何復制雲伺服器centos環境 瀏覽:984
債權pdf 瀏覽:301
紅色番字的app怎麼下載 瀏覽:876
雲伺服器流程教課 瀏覽:702
中國農業銀行app怎麼沒有網 瀏覽:997
幾率表演算法 瀏覽:902
程序員理工科 瀏覽:708
企業郵箱登錄收件伺服器地址 瀏覽:558
計算機思維與演算法設計的重要性 瀏覽:664
linux刷新磁碟命令 瀏覽:76
我的世界如何查看伺服器種子pc 瀏覽:284
linuxlamp編譯安裝 瀏覽:609
枚舉演算法ppt 瀏覽:184
cmd查看進程命令 瀏覽:956