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 (380 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 (380 points)
thanks for such a nice explanation.

Related Questions

+1 vote
2 answers 5,694 views
+1 vote
1 answer 776 views
+1 vote
2 answers 105 views
+4 votes
1 answer 161 views
+2 votes
1 answer 171 views
+2 votes
1 answer 1,367 views
+5 votes
1 answer 77 views
asked in Programming by jatin Expert (3,823 points)
+6 votes
2 answers 2,771 views

Not a Member yet?

Ask to Folks Login

My Account
519 Folks are online
1 members and 518 guest online
Your feedback is highly appreciated