too long

i am working on a project where i need to get the complete sentence between a html tag closest to a certain character.

for example:

in given example, if i search for Mark, then i want to print the complete sentence between the closest html tag.

<span>In paris (Mark Bartels) worked for about 10 years.</span>

is there a way to find the closest html tag to a certain character in php?

With jQuery:

var elem = $('body').find('> :contains(Mark)').not('script, style, link');

$('pre').html(elem.text());
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div><span><h3>In paris (Mark Bartels) worked for about 50 years.</h3></span></div> <div><span><h3>In paris (Mary Bartels) worked for about 50 years.</h3></span></div>
<br><br><br>
Result string is:<br>
<pre></pre>

</div>