1

i) I need to extract few elements from a html page using php.

ii) Am using html dom parser.

iii) I have been able to extract all **<a>**s, **<b>**s, **<li>**s, etc.

iv) How should I be able to extract elements of the type/enclosed within

**<td class = ""><a href = "">ABC</a></td>**

Anything using href, i.e. property of href

Note: I need to extract ABC

gir3191
  • 35
  • 5

2 Answers2

0

This might not be the answer you are looking for but, I have worked with phpquery before and found it to be a great tool to do that kind of work.

http://code.google.com/p/phpquery/

filype
  • 8,034
  • 10
  • 40
  • 66
  • 1
    I'm pretty sure phpquery is unmaintained and buggy. I would use PHP Simple HTML DOM Parser http://simplehtmldom.sourceforge.net/ – Petah Feb 27 '12 at 04:45
0

You will not get the entire structure using the DOM Parser.

You should use getAttribute() method for that purpose. Check here

Here is a simple example also

$markup = file_get_contents($someplace);
$dom = new DomDocument();
$dom -> loadHTML($markup);
$tds = $dom -> getELementsByTagName("td");
foreach($tds as $td) {
    echo $td -> getAttribute("class");
}
Starx
  • 77,474
  • 47
  • 185
  • 261