PHP Classes

File: example/example_remove_content_from_table.php

Recommend this page to a friend!
  Classes of Lars Moelleken   Simple HTML DOM   example/example_remove_content_from_table.php   Download  
File: example/example_remove_content_from_table.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Simple HTML DOM
Manipulate HTML elements using DOMDocument
Author: By
Last change:
Date: 1 year ago
Size: 610 bytes
 

Contents

Class file image Download
<?php

use voku\helper\HtmlDomParser;

require_once
'../vendor/autoload.php';

$templateHtml = '
<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>
'
;

// remove: "<br>" from "<ul>"
$htmlTmp = HtmlDomParser::str_get_html($templateHtml);
foreach (
$htmlTmp->findMulti('tr') as $tr) {
    foreach (
$tr->findMulti('.delete') as $spanDelete) {
       
$tr->outerhtml = '';
    }
}

$templateHtml = $htmlTmp->save();

// dump contents
echo $templateHtml;