如何去除某个 html 标签之前和之后的文本
基本上我想采取类似的操作:
textheretextheretexthere
<table>
<tr><td>heres some stuff</td><td>and some morestuff</td></tr>
</table>
moretextheremoretexthere
并删除此处的所有文本和此处的更多文本,只留下表格
Basically I want to take something like:
textheretextheretexthere
<table>
<tr><td>heres some stuff</td><td>and some morestuff</td></tr>
</table>
moretextheremoretexthere
and remove all the texthere and moretext here just leaving the table
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要使用
strpos
找到位置,然后使用
substr
删除此处的文本。然后对于 < code>当然,这根本不完美,我知道,但你得到了提示,你可以努力改进它,也许最终会得到一个可以帮助你解决问题的函数。
You need to find
<table>
position withstrpos
and then usesubstr
to remove the text to this point.and then the same for</table>
Of course this is not perfect at all,i know but you got the hint,you can work on improving it and maybe end up with a function that helps you solve your problem.
这将是最简单的方法。
http://yelotofu.com/2008/08/jquery-outerhtml/
This is would be the easiest way.
http://yelotofu.com/2008/08/jquery-outerhtml/