2

Suppose I have some html and I want to parse something from it. In my html I know A, and want to know what is in C . I start getting all td elements, but what to do next ?

I need to check something like " if this td has A as value then check what is written in third td after this. But how can I write it ?

$some_code = ('
....
<tr><td>A</td><td>...</td><td>c</td></tr>
.....
');
$doc->loadHTML($some_code);
$just_td = $doc->getElementsByTagName('td');

foreach ($just_td as $t) {
some code....
}

1 Answer 1

5

With XPath:

/html/body//tr/td[text()="A"]/following-sibling::td[3]

will find the third sibling of a td element with text content of A that is a child of a tr element anywhere below the html body element.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.