可用如下的代碼來(lái)實(shí)現(xiàn):

在漢中等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場(chǎng)前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供網(wǎng)站制作、網(wǎng)站建設(shè) 網(wǎng)站設(shè)計(jì)制作按需求定制制作,公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),成都品牌網(wǎng)站建設(shè),營(yíng)銷型網(wǎng)站建設(shè),成都外貿(mào)網(wǎng)站建設(shè),漢中網(wǎng)站建設(shè)費(fèi)用合理。
?php
$str1="|1234|#2354#@2314@
|1314|#2154#@2214@
|1234|#2354#@2314@
|1314|#2154#@2214@";
if(preg_match_all("/\|(\d{4})\|\#(\d{4})\#\@(\d{4})\@/m",$str1,?$out,?PREG_PATTERN_ORDER))
for($i=0;$icount($out[0]);$i++)
{
echo?"{'".$out[1][$i]."','".$out[2][$i]."','".$out[2][$i]."'}br/";
}
?
效果如下所示:
{'1234','2354','2354'}
{'1314','2154','2154'}
{'1234','2354','2354'}
{'1314','2154','2154'}
$string_1 = '
tr
td width=15% align=rightb電話:/b/td
td width=85%86666947/td
/tr
tr
td align=right b地址:/b/td
td 春熙路8號(hào)/td
/tr
tr
td align=right b人均:/b/td
td span class=f_red_14b14/span元/td
/tr
tr
td align=rightb菜系:/b/td
td快餐/小吃/td
/tr
'
;
preg_match_all ("|td[^]*([^(b)].*)/td|", $string_1, $out, PREG_PATTERN_ORDER);
print_r($out[1]);
---------------------------------------------------------
輸出結(jié)果為:
Array
(
[0] = 86666947
[1] = 春熙路8號(hào)
[2] = 快餐/小吃
)
現(xiàn)獲取此div的html串,然后處理。
例如:
ul
liMa hrMef="hMtMtp://xxx1" tarMget="_blaMnk" claMss=""/Ma/li
liMa hrMef="hMtMtp://xxx2" targMet="_blaMnk" claMss=""/Ma/li
/ul
正則:hMtMtp.+?(?=".+/a.*/li)
輸出:
hMtMtp://xxx1
hMtMtp://xxx2
(把上面大寫(xiě)的M都去掉)
用PHP正則表達(dá)式匹配,就可以提取class里面的數(shù)據(jù),并將no去除,完整的PHP程序如下
?php
$str='div?class="lot-nums"span?class="no7"/spanspan?class="no8"/spanspan?class="no5"/spanspan?class="no9"/spanspan?class="no2"/spanspan?class="no4"/spanspan?class="no6"/spanspan?class="no0"/spanspan?class="no3"/span?span?class="no1"/span/div';?
$regex='/span?class="no(\d+)"/i';?
preg_match_all($regex,$str,$result);?
print_r($result[1]);?
?
運(yùn)行結(jié)果
分享標(biāo)題:php正則抓取數(shù)據(jù) php正則測(cè)試
文章起源:http://chinadenli.net/article18/ddgcjdp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供移動(dòng)網(wǎng)站建設(shè)、網(wǎng)站內(nèi)鏈、網(wǎng)站維護(hù)、服務(wù)器托管、ChatGPT、微信小程序
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)