Get text from next tag

2019-02-24 06:35发布

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.

3条回答
做个烂人
2楼-- · 2019-02-24 07:10

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

查看更多
男人必须洒脱
3楼-- · 2019-02-24 07:18
preg_match('~<p>(.*)</p>~', $html, $matches);
var_dump($matches);
查看更多
戒情不戒烟
4楼-- · 2019-02-24 07:33

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.

查看更多
登录 后发表回答