php 匹配標籤內的文字內容 preg_match_all strip_tags
阿新 • • 發佈:2018-10-31
$str = "<p> BT特權說明: </p> <p> 1.充值比例1:500,首充送雙倍鑽石 </p> <p> 2.上線贈送滿級VIP,18888鑽石,100W金幣 </p> <p> 3.購買普通月卡,每日就可領取鑽石2000,永恆月卡僅需198,每日可領取鑽石12888 </p> <p> 4.首次鑽石召喚送稀有英雄,使用傳說召喚十連抽必得史詩英雄 </p> <p> 5.每日登陸即可領取豐厚的獎勵,最多可領取15天 </p> <p> 6.你衝級我送禮!凡混沌神等階達到一定要求,即可領取相應的獎勵,獎勵豐厚,不容錯過 </p> <p> 7.掌控眾神!拯救諸界!3天領魔神!7天拿無盡!15天領天使! </p>"; $search=array(" "," ","\t","\n","\r"); $str = str_replace($search, '', $str); preg_match_all('/<p.*?>(.*?)(?=<\/p>)/im', $str, $matches); if(!empty($matches[1])){ $arr = $matches[1]; }else{ $arr = explode('<br/>',$str); } foreach($arr as $v){ $search=array(" "," ","\t","\n","\r"); $v = str_replace($search, '', $v); $val = trim(strip_tags($v)); if(!empty($val)){ $bt_arrays[] = $val; } } $bt_arrays = array_filter($bt_arrays);