lucy24 - 9:13 pm on Apr 21, 2013 (gmt 0)
But this is only part of the code. You're not spitting the > back into raw html, are you? It may not be as instantly disastrous as a lone < but I'd really prefer to see it converted into into > before you let it loose on the world.
So structurally you've got two pieces.
First piece: replace all occurrences of "<br />" with something. Any one character will do, so long as it doesn't occur naturally in the text. Trim away the final occurrence of that character.
Second piece: replace all remaining "something" with "_>_" (using lowlines as a standin for literal spaces because Forums won't display spaces inside markup).