title: regex find <table> and modify
body: <p>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 <code>&lt;div&gt;</code> around it.</p>
  
  <pre><code>&lt;p&gt;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&lt;/p&gt;
  
  &lt;table&gt;
  &lt;thead&gt;
      &lt;tr&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;
      ...
  &lt;/tbody&gt;
  &lt;/table&gt;
  
  &lt;p&gt;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&lt;/p&gt; 
  &lt;table&gt;
  &lt;thead&gt;
      &lt;tr&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;
      ...
  &lt;/tbody&gt;
  &lt;/table&gt;
  ...
  </code></pre>
  
  <p>My goal is it now to give every <code>&lt;table&gt;</code> a <code>&lt;div class="table"&gt;</code></p>
  
  <p>I´ve tried it with regex and got this result:</p>
  
  <pre><code>function smarty_modifier_table($string) {
      preg_match_all('/&lt;table.*?&gt;(.*?)&lt;\/table&gt;/si', $string, $matches);
      echo "&lt;pre&gt;";
      var_dump($matches);
  }
  /* result
  array(2) {
      [0]=&gt; string(949) "&lt;table&gt;...&lt;/table&gt;"
      [1]=&gt; string(934) "&lt;thead&gt;...&lt;/tbody&gt;"
  }
  array(2) {
      [0]=&gt; string(949) "&lt;table&gt;...&lt;/table&gt;"
      [1]=&gt; string(934) "&lt;thead&gt;...&lt;/tbody&gt;"
  }
  */
  </code></pre>
  
  <p>First of all, I do not understand why the second <code>array [1]=&gt; string(934) "&lt;thead&gt;...&lt;/tbody&gt;"</code> appears
  and second how to fit the modified array back into the string on the right place.</p>