require 'QueryList/vendor/autoload.php';
use QL\QueryList;
//获取每个li里面的h3标签内容,和class为item的元素内容
$html =<<
xxx
item1item2xxx2
item12item22
STR;
$data = QueryList::Query($html,array(
'title' => array('h3','text'),
'list' => array('.list','html')
),'#demo li')->getData(function($item){
$item['list'] = QueryList::Query($item['list'],array(
'item' => array('.item','text')
))->data;
return $item;
});
print_r($data);
/**
结果:
Array
(
[0] => Array
(
[title] => xxx
[list] => Array
(
[0] => Array
(
[item] => item1
)
[1] => Array
(
[item] => item2
)
)
)
[1] => Array
(
[title] => xxx2
[list] => Array
(
[0] => Array
(
[item] => item12
)
[1] => Array
(
[item] => item22
)
)
)
)
*/