I have code on a side which looks like the one below and will be generated from a CMS.
The user can generate a table, but I have to put a <div>
around it.
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et
dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo
dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem</p>
<table>
<thead>
<tr><td></td></tr>
...
</tbody>
</table>
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et
dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo
dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem</p>
<table>
<thead>
<tr><td></td></tr>
...
</tbody>
</table>
...
My goal is it now to give every <table>
a <div class="table">
I´ve tried it with regex and got this result:
function smarty_modifier_table($string) {
preg_match_all('/<table.*?>(.*?)<\/table>/si', $string, $matches);
echo "<pre>";
var_dump($matches);
}
/* result
array(2) {
[0]=> string(949) "<table>...</table>"
[1]=> string(934) "<thead>...</tbody>"
}
array(2) {
[0]=> string(949) "<table>...</table>"
[1]=> string(934) "<thead>...</tbody>"
}
*/
First of all, I do not understand why the second array [1]=> string(934) "<thead>...</tbody>"
appears
and second how to fit the modified array back into the string on the right place.