Take the 2-minute tour ×

I have a html snippet that looks like this (of course surrounded by other html):

<p class="finfot3"><b>Header:</b></p>

How can I get Text from this? I'm using simple_html_dom, but I can use something else if simple_html_dom can't do this.

share|improve this question
add comment

3 Answers

up vote 3 down vote accepted

This is untested, but you might be looking for simple_html_doms next_sibling() method.

$html->find('p[class=finfot3]')->next_sibling()->innertext() should return the contents of the second <p> element.

share|improve this answer
next_sibling() did the trick. Thanks mate. –  Marwelln Feb 7 '11 at 11:47
add comment

Find the p element with the class. Then use

where $e is the element with the class.

For better alternatives to SimpleHtmlDom, see Best Methods to parse HTML

share|improve this answer
add comment
preg_match('~<p>(.*)</p>~', $html, $matches);
share|improve this answer
add comment

Your Answer


