+1 vote
in Programming by (440 points)

I am new in DOM and want to collect a particular node value of a div my environment is in PHP.

I am trying to get node values from DOM but not getting success, I hope any one of you help me out Thanks!


1 Answer

+1 vote
by Expert (5.9k points)
edited by
Best answer

DOM is a interface for the programming languages like HTML, XHTML and XML, Here we are talikg about HTML so in HTML DOM there is a node which contains some values which is called node values lets see a example :

Say we have a url : $domain = www.xyz.com


$doc = new DOMDocument();

// Get the sourcecode of the domain



//here we are collecting all div tags from web page

$div = $doc->getElementsByTagName('div');


foreach($books as $div)



$class = $div->getAttribute('class');

if (strpos($class, 'price') !== false)



echo $class->nodeValue;




In this example we are using PHP and printing all node values of class price.

by (440 points)
thanks for such a nice explanation.

Not a Member yet?

Ask to Folks Login

My Account

Your feedback is highly appreciated