PHP Simple HTML DOM解析器将该元素放在当前元素之后

时间:2018-10-18 16:26:10

标签: php simple-html-dom

我有这个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)
}

现在如何获取跨度NEXT的值(纯文本)到当前跨度。

注意:标签的顺序及其值在不断变化,有时是ADDRESS之前的TEL ...

1 个答案:

答案 0 :(得分:1)

您正在寻找nextSibling() http://simplehtmldom.sourceforge.net/manual_api.htm

if ($span->plaintext == 'Name:') {
    $name = $span->nextSibling()->plaintext;
}