Jump to content

array hierarchy and filter


ludo1960

Recommended Posts

I haven't done any php DOM manipulation or parsing in quite some time and as far as I can recall I've not used the Simple HTML Dom Parser library (usually just use DOMDocument), but from the docs it looks this could be what you're looking for:

foreach($html->find('li') as $li){
  print("<p>{$li->first_child()->innertext}</p>");
}

The first_child() of each list item element should be the anchor tag, and innertext should return the contents of that anchor tag. Unless I'm not reading something correctly - it's been a long day, so it's very possible that I am...

Link to comment
Share on other sites

Thanks again, changed a bit of your code and it works great

    for ( $i = 0 ; $i < count($li) ; $i++ ) {

        echo $li[$i]->children[0]->attr['href'] . '<br>' ; 
      
      	//echo $li[$i]->children[0]->children[0]->_[4] . '<br>' ; This was my effort lol!
      
      	echo $li[$i]->first_child()->innertext 
        
    } 

So now I have all I need to construct my associative array ! Great answer! thanks again Maxxd

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.