0

Im importing an XML feed as content onto my page with PHP. If the content has a spare open or closed div then it messes up my page:

<div>
<div>Stuff</div>
<div>Stuff</div>
<div>Stuff</div>

Or

<div>Stuff</div>
<div>Stuff</div>
<div>Stuff</div>
</div>

I cant remove all divs as they are needed for the layout of the content. With php can I remove any divs that either open but dont close, or close but dont open? Thanks

Evanss
  • 23,390
  • 94
  • 282
  • 505
  • Search is your friend. Have a look at this very similar question: [Parsing of badly formated HTML in PHP](http://stackoverflow.com/questions/2351526/parsing-of-badly-formated-html-in-php) – Cylindric Nov 28 '11 at 17:26

2 Answers2

1

You can use tidy, but as I understand it works best on complete pages.

jeroen
  • 91,079
  • 21
  • 114
  • 132
0

The most effective solution would probably be the use of the Tidy extension. It has several methods which will allow you to clean and repair markup.

In particular, you would want to look at tidy::cleanRepair, which should remove any broken tags, and produce "clean" output.

FrozenFire
  • 963
  • 1
  • 6
  • 15