voku / simple_html_dom

📜 Modern Simple HTML DOM Parser for PHP

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Remove content based on child element

itajackass opened this issue · comments

Hi i ond't find a way to remove a row table where a child has a class.

For example if I need to remove all rows with a cell with inside a span with class ".delete", i don't know how to do that.

<table>
<tr>
<td>
 text 1
</td>
<td>
 <span class="delete">DELETE</span>
</td>
</tr>
<tr>
<td>
 text 2
</td>
<td>
</td>
</tr>
<tr>
<td>
 text 3
</td>
<td>
 <span class="delete">DELETE</span>
</td>
</tr>
</table>

I tried this without success:

foreach ($dom->find('.delete').closest("tr") as $row) {
        $row->outertext = '';
    }

Sorry for not getting back to you sooner: here is an example 031f043