Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<tr> as HTMLNode #35

Closed
jampot5000 opened this issue Sep 28, 2015 · 1 comment
Closed

<tr> as HTMLNode #35

jampot5000 opened this issue Sep 28, 2015 · 1 comment

Comments

@jampot5000
Copy link

I have selected a table by finding it by class, I then need to loop over each row and examine the cells within them however returns as a TextNode so I am unable to do selects/foreach on the table cells .

Is there any way to make return as a HTMLNode?

@tegansnyder
Copy link

tegansnyder commented Apr 12, 2016

@jampot5000 curious why you closed this? Did you find a way to solve your issue? I'm able to do it like this:

require "vendor/autoload.php";
use PHPHtmlParser\Dom;

$html = <<<HTML
<table class="w3-table-all" style="width:100%">
<tbody>
<tr>
    <th>Number</th>
    <th>First Name</th>
    <th>Last Name</th>
    <th>Points</th>
</tr>
<tr>
    <td>1</td>
    <td>Eve</td>
    <td>Jackson</td>
    <td>94</td>
</tr>
<tr>
    <td>2</td>
    <td>John</td>
    <td>Doe</td>
    <td>80</td>
</tr>
</tbody></table>
HTML;

$dom = new Dom;
$dom->loadStr($html, []);

$contents = $dom->find('table.w3-table-all tr');

foreach ($contents as $content) {
    echo $content->innerHtml;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants