<?php
$specoffer = "http://www.msk.lenta.com/show/product/92003/";
libxml_use_internal_errors(true);
$doc = new DOMDocument();
libxml_clear_errors();
$doc->loadHTMLFile($specoffer);
$doc->saveHTML();
$doc->preserveWhiteSpace = false;
$xpath = new DOMXPath($doc);
$prices_name = "Цена: ";
$discounts_name = "Цена со скидкой: ";
$goodsnames_name = "Название: ";
$imglinks_name = "Ссылка на изображение: ";
$goodsdesriptions_name = "Описание: ";
$prices_value = $xpath->query("/html/body/div[1]/div/div/div/section/div/div/main/div[2]/div[2]/div[1]/div/span[2]");
$discounts_value = $xpath->query("/html/body/div[1]/div/div/div/section/div/div/main/div[2]/div[2]/div[1]/div/span[1]");
$goodsnames_value = $xpath->query("/html/body/div[1]/div/div/div/section/div/div/main/div[2]/div[2]/h3");
$imglinks_value = $xpath->query("/html/body/div[1]/div/div/div/section/div/div/main/div[2]/div[1]/a/img");
$goodsdesriptions_value = $xpath->query("/html/body/div[1]/div/div/div/section/div/div/main/div[2]/div[2]/p[1]");
$arr = array(
$prices_name => $prices_value,
$discounts_name => $discounts_value,
$goodsnames_name => $goodsnames_value,
$imglinks_name => $imglinks_value,
$goodsdesriptions_name => $goodsdesriptions_value
);
foreach($arr as $key => $value)
{
echo $key . $value->nodeValue . "<br />";
}
// Рабочий вариант
// foreach ($prices_value as $price) {
// echo "Цена: {$price->nodeValue} <br>";
// }
$prices_value = $xpath->query("//div/span[2]");
if($prices_value !== FALSE && $prices_value->length > 0)
echo $prices_value->item(0)->nodeValue; // тут ваше значение
$prices_value = $xpath->query('//div/span');
if($prices_value !== FALSE && $prices_value->length > 0)
{
foreach($items as $item)
echo $item->nodeValue;
}