php - preg_replace - Replacing <br> with nothing in <pre> tags
969
I have the following:
$newtext = preg_replace('@<pre>.*<br[/>]*?>?</pre>@si','',$text);
and I want it to replace all<br>, <br />, or <br/>
tags with nothing when between<pre>
tags, but it isn't working. What's wrong with it?
Answer
Solution:
Your problem is that you're trying to use regular expressions to do a parser's job. Even if you get it mostly working, you'll be finding edge cases where things break down the road.
See: RegEx match open tags except XHTML self-contained tags