i am working on a project where i need to get the complete sentence between a html tag closest to a certain character.
我正在开发一个项目,我需要在最接近某个字符的html标签之间获得完整的句子。
for example:
in given example, if i search for Mark, then i want to print the complete sentence between the closest html tag.
在给定的例子中,如果我搜索Mark,那么我想在最近的html标签之间打印完整的句子。
<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?
有没有办法在PHP中找到最接近某个字符的html标签?
1 个解决方案
#1
2
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>
#1
2
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>