I'm trying to replace certain occurances of a substring within certain substrings of a string.
For example, if I have the string:
"blah1<br>blah2 blah3 <pre>asdf<br>123<br></pre> blah4 blah5<br>blah6"
I would like to be able to use a preg_replace() call to change this to:
"blah1<br>blah2 blah3 <pre>asdf123</pre> blah4 blah5<br>blah6"
Where, in this example, <br>'s are removed, but only within <pre> blocks. Is this possible?
I'm not so great a PHP, and worse at regex; I came up with something like..
$str = preg_replace("/<pre>(.*)<br><\/pre>/", "<pre>$1</pre>", $str); But it doesn't exactly work correctly. I'm sure this is far from what I want to
Might anyone be regex gurus?