4

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

<p class="finfot3"><b>Header:</b></p>
<p>Text</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.

Marwelln
  • 28,492
  • 21
  • 93
  • 117

3 Answers3

5

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.

Leigh
  • 12,859
  • 3
  • 39
  • 60
1

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

Community
  • 1
  • 1
Gordon
  • 312,688
  • 75
  • 539
  • 559
0
preg_match('~<p>(.*)</p>~', $html, $matches);
var_dump($matches);
powtac
  • 40,542
  • 28
  • 115
  • 170