I need to reduce any more than one <br> or <br/> tags between two images to only one. It needs to be liberal enough to encounter any kind of attribute info in the images, any kind of whitespace between any of the elements and the two forms of breaks. Please note, I do not want to affect <br/> tags preceeding or trailing <img> tags, only those between two images.
This is what I’m using:
$content = preg_replace('/(<img[^>]*>)+\s*?(<br\/?>\s*?)+\s*?(<img[^>]*>)+/is','$1<br/>$3',$content);
Here’s an example
...
Some text here.<br>
<br><img src="http://www.domain.tld/image1.jpg"><br>
<img src="http://www.domain.tld/image2.jpg"><br><br/>
<img src="http://www.domain.tld/image3.jpg">
</div>
The pattern should only replace the 2 x <br> tags between image2 and image3.
I don’t know why my pattern isn’t working, can you see what I’m not?
Thanks for any help!
EDIT
FYI, I have no control over the original source material in $content.
This should work: