PHP 简单 HTML DOM 解析当前元素之后的元素
PHP Simple HTML DOM Parser the element just after current element
我有这个HTML:
<div class="card">
<span class="label">Name:</span><span>John Doe</span>
<span class="label">Address:</span><span>Some address...</span>
<span class="label">Email:</span><span>email@example.com</span>
<span class="label">Tel:</span><span>xxxxxxxxx</span>
</div>
$spans = $html->find('.label');
foreach ($spans as $span) {
if ($span->plaintext == 'Name:') $name = John Doe;
(ALWAYS THE SPAN NEXT TO THE CURRENT .label SPAN)
}
现在如何获取当前跨度的下一个跨度的值(明文)。
注意:标签的顺序及其值不断变化,有时 ADDRESS 之前的 TEL...
您正在寻找 nextSibling()
http://simplehtmldom.sourceforge.net/manual_api.htm
if ($span->plaintext == 'Name:') {
$name = $span->nextSibling()->plaintext;
}
我有这个HTML:
<div class="card">
<span class="label">Name:</span><span>John Doe</span>
<span class="label">Address:</span><span>Some address...</span>
<span class="label">Email:</span><span>email@example.com</span>
<span class="label">Tel:</span><span>xxxxxxxxx</span>
</div>
$spans = $html->find('.label');
foreach ($spans as $span) {
if ($span->plaintext == 'Name:') $name = John Doe;
(ALWAYS THE SPAN NEXT TO THE CURRENT .label SPAN)
}
现在如何获取当前跨度的下一个跨度的值(明文)。
注意:标签的顺序及其值不断变化,有时 ADDRESS 之前的 TEL...
您正在寻找 nextSibling()
http://simplehtmldom.sourceforge.net/manual_api.htm
if ($span->plaintext == 'Name:') {
$name = $span->nextSibling()->plaintext;
}