This is my first t" />
This is my first t" />
This is my first t"/>

DOMXpath query to get the value only to next span tag

16 Views Asked by At

I am reading in a page content with file_get_contents. This contains the following code

<div class="row">
    <div class="row1">
        <span>
            This is my first text
            <span class="xxx">mySubtext</span>
        </span>
        <a href="...">MyLink</a>
    </div>
    <div class="row1">
        <span>
            This is my first text 2
            <span class="xxx">mySubtext2</span>
        </span>
        <a href="...">MyLink</a>
    </div>
</div>

How can I output only the text up to the second SPAN?

I use the following code and get mySubtext as well

$headerData = $xpath->query('//div[@class="row"]/div[@class="row1"]');
foreach ($headerData as $header) {
    $value = $xpath->query('span', $header);
    $value = $value->item(0)->textContent;
    echo $value;
}

Edit: I have updated the code to show the header area as well

0

There are 0 best solutions below