I'm writing a chat program and what I want to do is replace all the html tags with > < tags but allow specific tags to still work (img, a etc.)
This is what I have so far but it does not appear to be working:
$value = '
<img src="/blah/blah.gif" />
<img src="/blah/blah.gif">
<b>blah</b>
<strong>test</strong>
<script>test</script>
<script>test
<script
type="text">
<script></script>
<script
>
</script>
<script>blah
<br />
';
$tags = 'b|img'; // allow these tags
echo preg_replace("~<((/(?!$tags)|(?!/)(?!$tags)).*?)>~is", '<$1>', $value);
The result of the output is this:
<img src="/blah/blah.gif" />
<img src="/blah/blah.gif">
<b>blah</b>
<strong>test</strong>
<script>test</script>
<script>test
<script
type="text">
<script></script>
<script
>
</script>
<script>blah
<br />
As you can see it doesn't appear to be stripping the
tag out as well even though this is not in the $tags
variable as an allowed tag.