I'm trying to find a way to strip tags from a user-inputted string except from tags that are wrapped in the [code] [/code] BB style tag.
For example, a user may enter this:
<script>alert("hacked");</script>
[code]<script>alert("hello");</script>[/code]
What I would like is the "hacked" alert to be removed, but not the "Hello" alert.
I would like to remove ALL tags (php, html, css, js) outside of the [code] but allow anything within them.
So far, I've got the following code to do the reverse of what I would like:
preg_replace('/\[code\](.*?)\[\/code\]/ise','strip_tags(\'$1\')',$code)