Simple HTML Dom - find text between divs

笑着哭i 提交于 2019-12-04 17:59:38

Use find('text', $index) to get all the text blocks, where $index is the index of the wanted text...

So in this case, it's:

echo $html->find('text', 3);

// OUTPUT:
The third of four performances in the Society's Morning Melodies series features...

You can read more in the Manual

EDIT:

Here's a working code:

$input = '<div class="left">
Bla-bla..
<div class="float">Bla-bla...
</div><!--/end of div.float-->
    <br />The third of four performances in the Society\'s Morning Melodies series features...<a href="index.php?page=tickets&month=20140201">&lt;&lt; Back to full event listing</a>
</div><!--/end of div.left-->';

//Create a DOM object
$html = new simple_html_dom();
// Load HTML from a string
$html->load($input);

// Using $index
echo $html->find('text', 3);

echo "<hr>";

// Or, it's the 3rd element starting from the end
$text = $html->find('text');
echo $text[count($text)-3];

// Clear DOM object
$html->clear();
unset($html);

// OUTPUT
The third of four performances in the Society's Morning Melodies series features...
The third of four performances in the Society's Morning Melodies series features...

Working DEMO

why dont you use ->plaintext on div.class? It outputs the text as needed.

$html->find("div[class=left]")->plaintext;

Martti

I actually think Simple HTML Dom does not provide tools to do this, as there is no "get before " or "get after" types of commands. If I am wrong, please let me know.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!