0

I am creating a mobile optimized version of a website, built dynamically through php. I have started using the php DOM and it seems to be what I am looking for.

I am having trouble writing all the child nodes of a div. I start with something like this

$DOM = new DOMDocument;
$DOM->loadHTML($html);
$divContents = $DOM->getElementById('c1');

lets say within $html the div c1 look like this:

<div id="c1">
   <img src="myimage.png" />
   <p>The div c1 contains this paragraph element</p>
   <span><strong>As well as these span and bolding elements</strong></span>
</div>

how can I extract the entire contents of c1, including tags and nodeValues and end up with and echo statement, or the equivalent that looks like this:

echo ' <img src="myimage.png" />
       <p>The div c1 contains this paragraph element</p>
       <span><strong>As well as these span and bolding elements</strong></span>';
hakre
  • 193,403
  • 52
  • 435
  • 836
JDV590
  • 651
  • 3
  • 15
  • 33
  • @MarcB I tried the innerHtml link you posted and it didn't work. I even tried altering it to some degree and the function returned nothing. – JDV590 Feb 23 '12 at 19:04
  • @JDV590: What you comment is *wrong*. I just tested against that solution and it perfectly works with your HTML sample as well. – hakre Jun 23 '13 at 22:02

0 Answers0