I have some database rows with a lot of text but I only want to select a specific text.
Example:
<strong>Lorem</strong>
<ul>
<li>Lorem</li>
<li>Ipsum</li>
</ul>
<strong>Ipsum</strong>
<ul>
<li>Ipsum</li>
<li>Lorem</li>
</ul>
<strong>Third</strong>
<ul>
<li>Some words</li>
<li>More words</li>
</ul>
I only want to select the Ipsum part with the ul element and ignore the rest. I was trying to work with DOMXPath->evaluate('//text()[contains()]')
but this only shows the Ipsum text and not the elements.
EDIT: The exact output I want is:
<strong>Ipsum</strong>
<ul>
<li>Ipsum</li>
<li>Lorem</li>
</ul>
The code I tried (I have tried more but this is the last result):
$d = new DOMDocument;
$d->loadHTML($text);
$x = new DOMXPath($d);
$result = $x->evaluate("//text()[contains(., 'Ipsum')]");
$result->item(0)->nodeValue;
This shows only the Ipsum text and not the list elements.