Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
以以下为例
<div id="XYZ"> <div id ="abc"></div> Text 1 <div id="efg"> Text 2 </div> Text 3 </div>
如何使用简单的 HTML DOM 解析器检索文本 1 和文本 2。
如果我使用 $text = $domOb->find(div[id=xyz])->plaintext;
$text = $domOb->find(div[id=xyz])->plaintext;
上面会给我全文。这件事我知道,但我被困在如何检索特定的文本部分。
解决此问题的最简单方法是将所需文本包装在<span>标签中并为其提供自己的 ID。因为 span 不是块元素,所以它不会破坏 HTML 页面的布局。
<span>