May 3, 2011

How should I get a div's content like this using dom in php?

Question by David

The div is like this

<div style="width:90%;margin:0 auto;color:#Black;" id="content">
this is text, severaltags
</div> 

how should i get the div’s content including the
tags using dom in php?

Answer by Starx

To get the values, you can try something like this

$doc = new DOMDocument();
$doc->loadHTMLFile('link-t0-html-file.php');
$xpath = new DOMXPath($doc);
$element = $xpath->query("//*[@id='content']")->item(0);
echo $element->nodeValue;

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!