简体   繁体   English

如何在php中找到最接近某个字符的html标签?

[英]How to find the closest html tag to a certain character in php?

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? 有没有办法找到最接近的html标签到 php中的某个字符

With jQuery: 使用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> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM