【发布时间】:2014-04-08 03:47:14
【问题描述】:
我需要知道如何遍历这个数组并获取 html 内容,以便我可以使用它来制作另一个数组。我的数组是这样的:
$arr = array(
"<span class='inside'>inside1</span> this is outside",
"<span class='inside'>inside2</span> this is outside",
"<span class='inside'>inside3</span> this is outside"
);
我想要以下结果:
$result = array(
"inside1",
"inside2",
"inside3"
);
我尝试了以下但没有结果:
foreach ( $arr as $html){
$dom = new DOMDocument();
$dom->loadHTML($html);
$xpath = new DOMXpath($dom);
$result = $xpath->query('//span[@class="inside"]');
echo $result
}
请帮忙。
【问题讨论】:
-
你试过什么?
-
我更新了我尝试过的内容
标签: php html arrays loops iteration