- var_dump: documentation ( source)
- preg_replace_callback: documentation ( source)
<?php
$content = <<<HTML
<table>
<thead>
<tr>
<th>1</th>
<th>2</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<table>
<thead>
<tr>
<th>A</th>
<th>B</th>
</tr>
</thead>
<tbody>
<tr>
<td>C</td>
<td>D</td>
</tr>
</tbody>
</table>
</td>
<td>4</td>
</tr>
</tbody>
</table>
HTML;
var_dump(
preg_replace_callback('~<table.*?</table>~is', function ($match) {
return '<div>' . $match[0] . '</div>';
}, $content)
);