简体   繁体   中英

get text from html with preg_match_all

i have htmlcode how to get the 700 mAh as array[0], BL-5CA as array[2], Nokia as array[3] using PHP. itry like this

preg_match_all('~<span>capacity(.*?)mAh~si', $result, $matches[0]);
preg_match_all('~<span>Model(.*?)</span></div>~si', $result, $matches[1]);
preg_match_all('~<span>Brand(.*?)</span></div>~si', $result, $matches[2]);

it shows me empty array. please help me to fix it

<div class="b-goods-specifications mod_cutted"> <div class="b-goods-specifications-item"> <ul class="b-goods-specifications-list"> <li class = "b-goods-specifications-row g-clearfix "> <div class="b-goods-specifications-cell"> <span> **capacity** </ span> </ div> <div class="b-goods-specifications-cell"> **700 mAh** </ div> </ li> <li class="b-goods-specifications-row g-clearfix"> <div class="b-goods-specifications-cell"> <span> **Model** </ span> </ div > <div class="b-goods-specifications-cell"> **BL-5CA** </ div> </ li> <li class="b-goods-specifications-row g-clearfix"> <div class = "b-goods-specifications-cell "> <span> **Brand** </ span> </ div> <div class="b-goods-specifications-cell"> **Nokia** </ div> </ li> <li class =" b-goods -specifications-row g-clearfix "> <div class="b-goods-specifications-cell"> <span> Type </ span> </ div> <div class="b-goods-specifications-cell"> Li -ion ​​</ div> </ li> </ ul> </ div> </ div>

Use PHP DOM , it will be simpler than regular expression.

http://php.net/manual/en/book.dom.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM