【发布时间】:2015-11-28 01:03:26
【问题描述】:
一个与其他人之前在这里提出的问题类似的问题,但由于我不知道如何应用这些建议,我需要一些帮助。
我想找到一个 html 文档的节点,它具有这样的结构(摘录,可能会有所不同):
<h2>My title 1</h2>
<h3>Sub-heading</h3>
<p>...<span><a href='#'>...</a></span></p>
<div>...</div>
<h2>My title 2</h2>
<p>No sub-heading here :O</p>
<h3>But here</h3>
<p>No link</p>
<h2>And so on...</h2>
<p>...</p>
我想要完成的是找到从一个 h2 到下一个 h2 之前的最后一项的所有节点,包括 h2 本身。在我的示例中,我想检索这样的“块”:
第 1 块:
<h2>My title 1</h2>
<h3>Sub-heading</h3>
<p>...<span><a href='#'>...</a></span></p>
<div>...</div>
第 2 块:
<h2>My title 2</h2>
<p>No sub-heading here :O</p>
<h3>But here</h3>
<p>No link</p>
第 3 块:
<h2>And so on...</h2>
<p>...</p>
除了 h2 之外,我没有其他目标(没有 id、没有我可以知道的文本内容、没有确定的内容等)。
【问题讨论】:
标签: php xpath domdocument