ok.... I'm parsing strings with tags, much like the one on this forum, which I've taken from a query.
for example - $query['string'] = '[url="www.google.com"]Google[/url] this is a test [b]bold text[/b]';
I'm then using wordwrap() to place <br> after every 60 characters.
And then using preg_replace() to replace all instances of [tag]text[/tag] with their html equivalent.
but the problem is sometimes I end up with [<br>tag]text[/tag], which I don't want. So before I parse the string through the second preg_replace() I use preg_replace() to switch all the instances of [<br>tag][/tag] (or any other place that <br> has been placed within the tag) with [tag]<br>text[/tag] thus placing the formatted text on a new line without messing up my html tags or going over the maximum allowed number of characters. But I'm having trouble writing a regular expression that does this.