Question

How do I get the $10.99 without getting the $11.50?

my code gets both and I do not want what's in the strike tag:

$price = trim($tmp_xpath->query("//div[@class='ProductPriceRating']/em")->item(0)->nodeValue);

here's the html:

<div class="ProductPriceRating">
    <em><strike class="RetailPriceValue">$11.50</strike> $10.99</em>
    <span class="Rating Rating5"><img src="images/IcoRating5.gif" alt="" style="" /></span>
</div>
Was it helpful?

Solution

Just get the text() of em element:

//div[@class='ProductPriceRating']/em/text()

Here's what you would have for $price:

$price = trim($tmp_xpath->query("//div[@class='ProductPriceRating']/em/text()")->item(0));

Or, as @adamretter noted, better use normalize-space() instead of trim():

$price = $tmp_xpath->query("normalize-space(//div[@class='ProductPriceRating']/em/text())")->item(0);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top