tags:

views:

147

answers:

2

i am using DOMDocument class, to parse HTML document in PHP. the code of table i am using...

<table>
   <tr>
      <td> 123 employees </td>
   </tr>
   <tr>
      <td> $50,000 </td>
   </tr>
</table>

i am not able to fetch nodeValue of the tag, which are like in the above format, i.e ($50,000, 123 employees ).

A: 

Maybe you could use XPath queries. For example:

$doc = new DOMDocument();
$doc->loadHTML(...your html...);

$xpath = new DOMXPath($doc);
$query = '//table/tr/td';

$entries = $xpath->query($query);

foreach ($entries as $entry)
    print_r($entry->nodeValue); (*)

Just replace the line marked with (*) with code that suites your needs. Cheers.

aefxx
A: 

It's hard to say what you are doing wrong if you don't say, what you are doing at all.

But in principle you must get a reference to the table (as a DOM element), then get the rows and cells (child nodes) and get the node value from there.

If your table is the only one in the document, you'll get it via $doc->getElementsByTagName('table')->item(0) (with $doc being the DOM document object).

GodsBoss