Jump to content
ludo1960

array hierarchy and filter

Recommended Posts

Yeah, got lots to learn. Wouldn't want it any other way! At least I try, that's got to count for something? 

Share this post


Link to post
Share on other sites

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...

  • Great Answer 1

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

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.