Header:

...">

Get text from next tag

I have an html snippet that looks like this (of course, surrounded by another html):

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

How can I get Text from this? I use simple_html_dom, but I can use something else if simple_html_dom cannot do this.

+3
source share
3 answers

This is not verified, but you can look for the simple_html_doms next_sibling() method.

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

+5
source

Find the element p with class. Then use

where $e is an element with a class.

For the best alternatives to SimpleHtmlDom, see Best HTML Parsing Techniques.

+1
source
 preg_match('~<p>(.*)</p>~', $html, $matches); var_dump($matches); 
0
source

All Articles