PHP删除元素前后的文本

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.

As your trying to get 2 nodes, the way I've done it is to use 2 XPath expressions...

$d = new DOMDocument;
$d->loadHTML($text);

$x = new DOMXPath($d);
$result = $x->evaluate("//strong[contains(., 'Ipsum')]");
$result1 = $x->evaluate("//strong[contains(., 'Ipsum')]/following-sibling::ul");

echo $d->saveHTML($result->item(0)).PHP_EOL;
echo $d->saveHTML($result1->item(0)).PHP_EOL;

Which outputs.

<strong>Ipsum</strong>
<ul>
<li>Ipsum</li>
    <li>Lorem</li>
</ul>

You can use preg_match.
It's not an ideal tool for HTML and XML but it can work with strict enough patterns.

This pattern captures strong tag with Ipsum and down to next strong tag or end of string.

$re = '/(<strong>Ipsum<\/strong>.*?)(<strong>|\z)/s';
$str =  '<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>';

preg_match($re, $str, $match);

var_dump($matches);

https://regex101.com/r/s0n0Em/2