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

Popular Categories





I want parse and process HTML and XML in PHP?

0 votes
144 views
asked in Programming by navneet (270 points)

Can you help me i am trying to parsing HTML and XML and extract information ?

1 Answer

0 votes
answered by PRASHANT PATEL (300 points)
edited by Bhartesh

For parsing you can use HTML DOM to retrieve data , Like you can load DOM and can iterate the nodes as per your need for example

$doc = new DOMDocument();

// Get the sourcecode of the domain

@$doc->loadHTMLFile($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;

 

}

}

 

For more understanding  you can see this Answer.

 

you also can use this script .

 

http://sourceforge.net/projects/simplehtmldom/files/

 

Related Questions

+1 vote
2 answers 89 views
+1 vote
2 answers 5,424 views
+2 votes
1 answer 147 views
+6 votes
3 answers 6,852 views
+4 votes
5 answers 732 views
0 votes
1 answer 9,863 views
+2 votes
3 answers 292 views
asked in Programming by jatin Expert (3,823 points)
+2 votes
1 answer 153 views
+4 votes
1 answer 628 views

Not a Member yet?

Ask to Folks Login

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