1

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.

askedMar 29, 2013 at 5:10
softleaks's user avatar
0

2 Answers2

1

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.

answeredMar 29, 2013 at 5:16
web-nomad's user avatar
Sign up to request clarification or add additional context in comments.

Comments

0

Try this code

$dom = new DOMDocument();$dom->loadHTML($html);$elements = $dom->getElementsByTagName('a');foreach ($elements as $child) {    echo $child->nodeValue;}
answeredMar 29, 2013 at 5:19
Praveen kalal's user avatar

1 Comment

This returnsall anchors, not only the ones between comments

Your Answer

Sign up orlog in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to ourterms of service and acknowledge you have read ourprivacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.