simple html dom - find within a find

1378 views php
1

I need some help with simple_html_dom.

I am trying to parse a data table with many table rows. Inside some of the td cells there is some further div tags that I need to parse separate.

    foreach($html->find('tr.statistics') as $data) {
    $cell_one = $data->find('td', 0)->plaintext;
    $cell_two = $data->find('td', 1)->plaintext;
    $cell_three = $data->find('td', 2)->innertext
    }

this works as it should, but i further need to find two div tags in $cell_three.

$cell_three data looks like this

<div id="_Div_Line85">65</div><div id="_Div_Line95">56</div> 

So my question is, how would I go about getting the contents within those two div tags?

answered question

So you need to strip out the HTML and only have 65 and 56?

that is correct, i am trying to get both numbers into there own variables

1 Answer

1

You need to loop through $cell_three.

foreach($html->find('tr.statistics') as $data) {
        $cell_one = $data->find('td', 0)->plaintext;
        $cell_two = $data->find('td', 1)->plaintext;
        $cell_three = $data->find('td', 2);
        foreach($cell_three as $subdata){
           $sub_1 = $subdata->find('td', 1)->plaintext;
           $sub_2 = $subdata->find('td', 2)->plaintext;
           }
        }

posted this

Have an answer?

JD

Please login first before posting an answer.

Ads

Categories