Jump to content

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

  • Great Answer 1

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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