0

我有 html 代码如何使用 PHP 将 700 mAh 作为数组 [0]、BL-5CA 作为数组 [2]、诺基亚作为数组 [3]。像这样

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]);

它向我显示了空数组。请帮我修复它

<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 ​​&lt;/ div> </ li> </ ul> </ div> </ div>
4

1 回答 1

1

使用PHP DOM,它会比正则表达式更简单。

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

于 2013-02-15T16:55:58.637 回答