title: Regex with php, using preg_replace replecates input and nests it inside of a div
body: <p>I've been trying to replace code-tags with divs that contain the classes I need. </p>
  
  <p>I use JS to create the tags with a press of a button, this works fine, and I'm able to insert the tags as many times as I'd like.</p>
  
  <pre><code>code.addEventListener("click", function() {
      let val = contentBox.value + "\[code\]\[/code\]"  
      contentBox.value = val;
  });
  </code></pre>
  
  <p>The problem only occurs when I'm trying to have php replace the tags.</p>
  
  <p><a href="https://imgur.com/a/PIFjnuU" rel="nofollow noreferrer">link to image</a> (can't post images seeing that I've yet to achive 10 reputation)
  As you can see in the picture, the returned regex is completely off. I've read about preg_* functions and I've used <a href="https://regex101.com" rel="nofollow noreferrer">regex101</a> to look at the regex I parse. I'm not really sure what I've done wrong as I'm really new to regex.</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;form method="post"&gt;
      &lt;input type="text" name="title" placeholder="title" required&gt; &lt;br&gt;
      &lt;input type="file" name="postimage" placeholder="postimage" &gt;&lt;br&gt;
      &lt;input type="text" name="category" placeholder="category" required&gt;&lt;br&gt;
      &lt;input type="button" id="code"&gt;Code&lt;/button&gt;
      &lt;input type="button" id="link"&gt;Link&lt;/button&gt;
      &lt;input type="button" id="test"&gt;Test&lt;/button&gt;
      &lt;textarea required placeholder="content" name="content" id="contentBox" style="height: 100px; width: 100%; resize: none;"&gt;&lt;/textarea&gt;
      &lt;input type="submit" value="submit" name="submit"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <pre class="lang-php prettyprint-override"><code>if(isset($_POST["submit"])) {
      $content = $_POST["content"];
      $open = preg_replace('/\[code\]/i', '&lt;div class="code"&gt;', $content);
      $close = preg_replace('/\[\/code\]/i', "&lt;/div&gt;", $content);
      $code = preg_split('/\[code\](.*?)\[\/code\]/m', $content);
  }
  
  </code></pre>
  
  <p>I expect the output to have replaced the code-tags with the correct divs. And to ignore everything outside the code-tags. </p>
  
  <p>Hope this all made any sense, if I've forgotten to include anything that might come in handy I'll do that upon request.</p>