HTML:
<div class="something" data-a="abc">ddsf</d>
PHP:
foreach ($dom->find('.something[data-rel]') as $this) {
var_dump($this->attr());
}
I tried this but error. Couldn't find any info on its documentation. I want to get the data-a
's value which is abc.
Why not just use the well-documented, built in, DOM extension?
$html = '<div class="something" data-a="abc">ddsf</div>';
$dom = new DOMDocument();
$dom->loadHTML($html);
$xpath = new DOMXPath($dom);
$nodes = $xpath->query('//div[@class="something"]/@data-a');
foreach ($nodes as $node) {
var_dump($node->value);
}
string(3) "abc"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With