0

I am trying to parse a HTML table in a page.

However, it is not the only TABLE in the page, and I am only interested in parsing the 2nd <table> instnace in the HTML page.

How do I specify to parse only the 2nd TABLE instance in the HTML page?

//the table by its tag name  
$tables = $dom->getElementsByTagName('table');   

1 Answer 1

2

Use DOMNodelist->item() (item() expects as argument the index, it's zero-based so 1 will return the 2nd table )

 $table = $dom->getElementsByTagName('table')->item(1);   
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy 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.