how to get reference of node where there is id attribute set from an entire HTML documents using php (domdocument)?
<div id='foo'>
lorem ipsum
</div>
<div id='bar'>
lorem ipsum
</div>
<div id="baf">
<div id="alpha">
lorem ipsum
</div>
</div>
i want to get list of foo,bar,baf,alpha nodes. nodes can be arbitrarily existed.
You can just use str_get_html
$html = '<div id="foo">
lorem ipsum
</div>
<div id="bar">
lorem ipsum
</div>
<div id="baf">
<div id="alpha">
lorem ipsum
</div>
</div>';
$html = str_get_html($html);
foreach ( $html->find("div") as $value ) {
var_dump($value->id);
}
Output
string 'foo' (length=3)
string 'bar' (length=3)
string 'baf' (length=3)
string 'alpha' (length=5)