user1236470
user1236470

Reputation: 11

Simple html dom - all tr except the first one

I would like to find all <tr> starting from the second, but i don't know how to get it right..

$items = $html->find('tr');

That piece of code gets all trs but i want everyone except the first one because that one contains <th>.

Upvotes: 1

Views: 1915

Answers (5)

Codesen
Codesen

Reputation: 7832

You can get all trs from $html->find('tr'); from this u can add the condition to ignore the if the next element for object is "th" tag then u can ignore that tr.

Upvotes: 0

redwind
redwind

Reputation: 161

if Simple html dom work like Jquery, try to use like this:

$items = $html->find('tr:not(:has(th)');

Upvotes: 1

inquam
inquam

Reputation: 12932

As PoulsQ suggests you CAN do it like

$firstTr = true;

foreach($html->find('tr') as $tr) {
  if(!$firstTr) {
    // YOUR LOGIC FOR A TR HERE
  }
  else {
    $firstTr = false;
  }
}

But I think it would be nicer code if you query the DOM to ignore the first element.

Upvotes: 0

xiaowl
xiaowl

Reputation: 5207

Just cut off the first element.

$items = array_slice($html->find('tr'), 1)

Upvotes: 7

PoulsQ
PoulsQ

Reputation: 2016

When you get your list with $html->find('tr'); make a loop that don't care of the first "index/row".

Upvotes: 1

Related Questions