0

I have this 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 protected]</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)
}

Now how to get the value (plaintext) of the span NEXT to the the current span.

NB: The order of the labels and their values is continuously changing, sometimes the TEL before ADDRESS...

1 Answer 1

1

You are looking for nextSibling() http://simplehtmldom.sourceforge.net/manual_api.htm

if ($span->plaintext == 'Name:') {
    $name = $span->nextSibling()->plaintext;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.