Thank you. I'm trying this but with str_replace also replace <div>&nbsp;</div> that are in middle of content that I want preserve it. I want only replace those that are on top and bottom not in middle. Have you an idea?
–
paganottiNov 17 '12 at 14:32

So, you want to replace only the <div> </div> part but, not what is in the middle like &nbsp; is that right?
–
anonNov 17 '12 at 15:03

Not exactly. I want delete entire tag <div>&nbsp;</div> but only those are present on top and bottom of html. if you see example above 5 "<div>&nbsp;</div>" are present in html string. I want remove first,second "<div>&nbsp;</div>" then fourth and fifth. It must remain third because it is located between "<div>I want remove empty div tag on top and bottom</div>" and "<div>other content</div>"
–
paganottiNov 17 '12 at 15:23

@Eritrea read one more time whole question... he wants to delete whole empty div parts... but not between filled divs
–
vlcekmi3Nov 17 '12 at 15:25