0

I can't work out how to get the contents of the second span 'cantfindme' using php simple html dom parser(http://simplehtmldom.sourceforge.net/manual.htm). Using the code below I can get the contents of the first span 'dontneedme'. I cant seem to get anything from second span at all.

$html =  str_get_html('<html><body><table><tr><td class="bar">bar</td><td><div class="foo"><span class="dontneedme">Hello</span></div></td></tr><tr><td class="bar">bar</td><td><div class="foo"><span class="cantfindme">Goodbye</span></div></td></tr></body></html>');
foreach($html->find('.foo', 0) as $article) 
{

    echo "++</br>";
    echo $article->plaintext;
    echo "--</br>";
}

Can anyone see where I'm going wrong?

2
  • Can you verify you need the content from both spans in the div element with class foo? Commented Feb 16, 2010 at 21:26
  • No I only need the second one but for some reason I can't select it using the class 'cantfindme'. There are also multiple 'cantfindme's in the document so it thought i would select it by using the foo class. Commented Feb 16, 2010 at 21:29

1 Answer 1

1

Try using this selector.

$html->find('div.foo .cantfindme');

Check out the documentation for more examples.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, that did it, you've been a great help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.