3v4l.org

run code in 300+ PHP versions simultaneously
<?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) );
Output for 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.13
string(812) " <div><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></div> </td> <td>4</td> </tr> </tbody> </table>"

preferences:
75.35 ms | 408 KiB | 5 Q