Need a regex for preg_replace.
This question wasn't answered in "another question" because not all tags I want to remove aren't empty.
I have not only to remove empty tags from an HTML structure, but also tags containing line breaks as well as white spaces and/or their html code.
Possible Codes are:
<br />            
BEFORE removing matching tags:
<div>
<h1>This is a html structure.</h1>
<p>This is not empty.</p>
<p></p>
<p><br /></p>
<p> <br /> &;thinsp;</p>
<p> </p>
<p> </p>
</div>
AFTER removing matching tags:
<div>
<h1>This is a html structure.</h1>
<p>This is not empty.</p>
</div>
I'm not so good with regex but, try this
Basically matches
You can use the following:
And replace with
''
(empty string)See DEMO
Note: This will also work for empty html tags with attributes.
Use tidy It uses the following function: