Hey there! any question in your mind? Ask It Now!.

Popular Categories

How to get node or node value from HTML DOM(Document Object Model).

+1 vote
asked in Programming by nishant (420 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
answered by duke Expert (5,813 points)
edited by Bhartesh
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.

commented by nishant (420 points)
thanks for such a nice explanation.

Related Questions

+1 vote
2 answers 6,533 views
+1 vote
1 answer 949 views
+1 vote
2 answers 184 views
+4 votes
1 answer 222 views
+2 votes
1 answer 224 views
+5 votes
1 answer 130 views
+6 votes
2 answers 3,554 views

Not a Member yet?

Ask to Folks Login

My Account
326 Folks are online
0 members and 326 guest online
Your feedback is highly appreciated