I've been trying to replace code-tags with divs that contain the classes I need.
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.
code.addEventListener("click", function() {
let val = contentBox.value + "\[code\]\[/code\]"
contentBox.value = val;
});
The problem only occurs when I'm trying to have php replace the tags.
link to image (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 regex101 to look at the regex I parse. I'm not really sure what I've done wrong as I'm really new to regex.
<form method="post">
<input type="text" name="title" placeholder="title" required> <br>
<input type="file" name="postimage" placeholder="postimage" ><br>
<input type="text" name="category" placeholder="category" required><br>
<input type="button" id="code">Code</button>
<input type="button" id="link">Link</button>
<input type="button" id="test">Test</button>
<textarea required placeholder="content" name="content" id="contentBox" style="height: 100px; width: 100%; resize: none;"></textarea>
<input type="submit" value="submit" name="submit">
</form>
if(isset($_POST["submit"])) {
$content = $_POST["content"];
$open = preg_replace('/\[code\]/i', '<div class="code">', $content);
$close = preg_replace('/\[\/code\]/i', "</div>", $content);
$code = preg_split('/\[code\](.*?)\[\/code\]/m', $content);
}
I expect the output to have replaced the code-tags with the correct divs. And to ignore everything outside the code-tags.
Hope this all made any sense, if I've forgotten to include anything that might come in handy I'll do that upon request.