Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DomDocument fetch h1 tag

I have very very big html page/data. I need to fetch data under h1 tag. so what I have seen on various example is DOMDOCUMENT is basically used for parsing xml. but if i have html data, very meshu, and I want to fetch text under <h1></h1> tag then what will be code.

If there are number of <h1> tags

$doc = new DOMDocument();

@$doc->loadHTML($this->siteHtmlData);

$aElements = $doc->getElementsByTagName("h1")

Please help me.

Thanks

like image 365
Dinesh Goyal Avatar asked Jan 01 '26 05:01

Dinesh Goyal


1 Answers

You could loop it to get the value:

foreach ($aElementsas as $node) {
    echo $node->nodeValue, PHP_EOL;
}
like image 127
xdazz Avatar answered Jan 02 '26 20:01

xdazz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!