Can I fetch the data between two html comments using Simple HTML Dom ??
For example, See the below code:
<!-- start of comment --><a href="link1.html">link1</a><br /><a href="link2.html">link2</a><br /><a href="link3.html">link3</a><br /><a href="link4.html">link4</a><br /><!-- end of comment--><a href="link5.html">link5</a><br /><a href="link6.html">link6</a><br />There are totally six links and only 4 links are enclosed within a "" and "" tags.
I just want to get the links between the comment tags.
2 Answers2
You can do this:
//get all comments$comments = $html->find('comment');...and usenext_sibling() to get next element and check if it's an anchor tag till you get another comment tag, where the script will terminate.
Sign up to request clarification or add additional context in comments.
Comments
Try this code
$dom = new DOMDocument();$dom->loadHTML($html);$elements = $dom->getElementsByTagName('a');foreach ($elements as $child) { echo $child->nodeValue;}1 Comment
JKB
This returnsall anchors, not only the ones between comments
Explore related questions
See similar questions with these tags.