Forum Moderators: coopster

Message Too Old, No Replies

Use php DOM functions to get class value

Anybody knows about DOM?

         

aha7

10:30 am on May 29, 2007 (gmt 0)

10+ Year Member



Hello,

Say, that I have an HTML page with many tables and with each table has a unique class (styling) for its rows that is different from other tables'. I use the dom class (DomDocument()) in PHP to load the HTML page for other purposes but it would be nice if I could achieve this using dom functions as follows:

I want to get the attribute "class" (its value) of the first, and only the first, childnode (<tr>) of each table on the page. Note: each <tr> element in all tables has its own class attribute with unique value to each table. All the rows (<tr>'s) of the same table has the same value for their class attribute.

How can I do that?

eelixduppy

12:45 pm on May 30, 2007 (gmt 0)



I haven't done too much with PHP's DOM functions, but this should help get you started. You should loop through by getting the tables by their tag name [php.net], take the first child of that node, and then retrieve the value of the class with getattribute [php.net].

Not a full solution, but it sounds good ;)

Good luck! If you find a solution, please do share :)