Using next_sibling() in PHP Simple HTML DOM Library?

4.4k Views Asked by At

I have a table of data, I want to capture the text inside of the element that immediately follows a element that has a label inside with a title attribute of "label". See the table here:

<table>
<tr>
    <th><label title="Country">Country</label></th>
    <td>I want to capture this text</td>
</tr>
<tr>
    <th><label title="Other">Heading I don't need</label></th>
    <td>Cell I don't Need</td>
</tr>
</table>

The only identifiable characteristic I can find is that the td is preceded by a th that has a label inside that has a unique title attribute.

First, I tried it without the label since I know it's going to be the first result for:

$found = $html->find('tr th')->next_sibling();
echo($found[0]);

But that doesn't appear to be the correct usage of next sibling. Can somebody tell me how to correctly use it to get the element that follows a element? Even better if there is someway to incorporate that label with its unique title attribute.

1

There are 1 best solutions below

3
On

Can somebody tell me how to correctly use it to get the element that follows a element?

Next sibling does not return its content. Instead u should use first_child().

Even better if there is someway to incorporate that label with its unique title attribute.

What do you mean 'to incorporate' ? You can use find() to get contents of every label nevertheless it has title or not. If you want to get content of a label with specified title then you should mention your title in find(). I suggest you to read the manual: http://simplehtmldom.sourceforge.net/manual.htm