Welcome Guest, Not a member yet? Register   Sign In
[PHP DOM] get all span elements inside a specific element
#1

[eluser]jant90[/eluser]
This is more a general PHP question than a CI one, but it's for an application I'm working on inside the CI framework so I decided I would ask for help on this forum Smile.

I'm trying to get all span elements inside a table from a certain HTML page. The table had an unique ID and therefore I can get it as follows:
Code:
$doc->getElementById("table_id");

Now I want all spans inside that table so I can read the nodeValues, if I wanted to get all of them inside the HTML page I would use:
Code:
foreach($doc->getElementsByTagName('span') as $data) {
  echo $data->nodeValue;
}

How do I make sure I only get the spans inside table_id?
#2

[eluser]jant90[/eluser]
Wow, I don't see why I didn't got this at first:

Code:
$doc->getElementById("table_id")->getElementsByTagName('span');

I think I tried this once but made some kind of mistake and thought I didn't work. Oh well, solved!




Theme © iAndrew 2016 - Forum software by © MyBB