0

I have a html table with multiple rows and each row with multiple columns. A Sample for one row looks like this.

<table class ="classt">
    <tbody>
        <tr class="row">
            <td height="20" valign="top" class="mosttext-new">data</td>
            <td height="20" valign="top" class="mosttext-new"> data</td>
            <td height="20" valign="top" class="mosttext-new">data</td> 
        </tr>
    </tbody>
</table>

I am trying to extract all td elements like this in a php script.

foreach($html->find('table.classt') as $e){
         foreach ($e->find('tr.row') as $tr){
            foreach ($tr->find('td') as $td){
                    $text = $td->innertext;
            }
        }
    }

But in $tr I am not getting row details with td tags. It is just coming the entire row withing double quotes like this

"data data data"

so my third loop is not able to find td as $tr does not have td tags.

Any idea on this?

0

1 Answer 1

5

I think you have to mention the class name after the 'td' followed by '.' like this

 foreach ($tr->find('td.mosttext-new') as $td)

Hope this should solve your problem. All the best.

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

1 Comment

so my third loop is not able to find td as $tr does not have td tags. From this line what you actually asking? Could not understand what really is your issue. Can you update what output you are expecting?. I tried with your code it's working fine. Update your question then i will answer furtherly.

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.