Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the text between two spans with "Simple HTML DOM"

Tags:

html

dom

text

php

Basically, I need to get the text between two span tags, and I've tried a bunch of different methods with no solution. I'm using Simple HTML DOM Parser (http://simplehtmldom.sourceforge.net/) too, so what I can do is a little restricted to. Here is the basic setup:

<span class=1>text here</span> TEXT I NEED TO GET <span class=2>more text</span>

Any help?

like image 214
spykr Avatar asked Apr 30 '26 17:04

spykr


1 Answers

The text between the span elements should be a DOMTextNode and sibling to the span elements. If SimpleHTMLDom follows DOM specs you should be able to get it with:

$text = $html->find('span[class=1]', 0)->next_sibling();

If that doesnt work, consider using a more proper parser that is based on libxml, e.g. see

  • How do you parse and process HTML/XML in PHP?
like image 148
Gordon Avatar answered May 03 '26 07:05

Gordon