我正在使用这个html解析器,它正在搜索HTML元素并在屏幕上打印出来
有些是ID,有些是H4
现在问题是它找到了一个ID,它找了一个H4
现在当我为每个循环结束时只有H4出现而不是一个价格
我想知道为什么会发生这种情况
我是新手并且热爱PHP,但我不明白为什么密钥正在重置并伪造ID密钥
CODE =>
<?php
ini_set('memory_limit','128M');
set_time_limit(0);
include_once('simple_html_dom.php');
$target_url= "ethicon2.html";
$html = new simple_html_dom();
$html -> load_file($target_url);
$line = 0;
$ref = $html-> find('.price');
$ref = $html-> find('h4');
$ref = $html-> find('h4');
foreach ($ref as $value) {
print "$value<br>";
}
?>
答案 0 :(得分:1)
尝试将它们添加到数组中,如下所示:
$ref[] = $html-> find('.price');
$ref[] = $html-> find('h4');
$ref[] = $html-> find('h4');
修改强> 如果您希望这些出现在一个数组中,请尝试使用
$ref2 = array();
foreach($ref as $r)
{
$ref2 = array_merge($ref2,$r);
}
print_r($ref2);