$queryItem = $xpath->query('//div[@class="catalog__item"]');
foreach ($queryItem as $goodsItem) {
$result[] = $goodsItem = array (
"queryName" => ($xpath->query('//a[@class="goods__title"]', $goodsItem)),
"queryPrice" => $xpath->query('//span[@class="price_block__cur-price"]', $goodsItem),
"queryDiscount" => $xpath->query('//span[@class="price_block__old-price"]', $goodsItem),
"queryImglink" => $xpath->query('//img[@class="catalog__item__image"]/@src', $goodsItem),
"queryDesription" => $xpath->query('//div[@class="catalog__item__text"]/p', $goodsItem)
);
}
var_dump($result);
$specoffer = "source/specoffers.html";
libxml_use_internal_errors(true);
$doc = new DOMDocument();
$doc->loadHTMLFile("$specoffer");
libxml_clear_errors();
$doc->saveHTML();
$doc->preserveWhiteSpace = false;
$xpath = new DOMXPath($doc);
//Queries by classNames
$queryItem = $xpath->query('//div[@class="catalog__item"]');
foreach ($queryItem as $goodsItem) {
$result = array (
$goodsItem = array (
"queryName" => $xpath->query('//a[@class="goods__title"]', $goodsItem),
"queryPrice" => $xpath->query('//span[@class="price_block__cur-price"]', $goodsItem),
"queryDiscount" => $xpath->query('//span[@class="price_block__old-price"]', $goodsItem),
"queryImglink" => $xpath->query('//img[@class="catalog__item__image"]/@src', $goodsItem),
"queryDesription" => $xpath->query('//div[@class="catalog__item__text"]/p', $goodsItem)
)
);
}
var_dump($result);
//Queries by classNames
$queryList = $xpath->query('//div[@class="cleara"]');
$queryItem = $xpath->query('//div[@class="catalog__item"]');
$queryNames = $xpath->query('//a[@class="goods__title"]');
$queryPrices = $xpath->query('//span[@class="price_block__cur-price"]');
$queryDiscounts = $xpath->query('//span[@class="price_block__old-price"]');
$queryImglinks = $xpath->query('//img[@class="catalog__item__image"]/@src');
$queryDesriptions = $xpath->query('//div[@class="catalog__item__text"]/p');
//Massive
$queryList = array(
$keyItem => $queryItem = array(
$keyName => $queryNames->item(0)->nodeValue,
$keyPrice => $queryPrices->item(0)->nodeValue,
$keyDiscount => $queryDiscounts->item(0)->nodeValue,
$keyImgurl => $queryImglinks->item(0)->nodeValue,
$keyDescription => $queryDesriptions->item(0)->nodeValue
)
);
//Loops for massives
foreach ($queryList as $keyItem => $queryItem) {
foreach ($queryItem as $key => $value) {
}
}
var_dump($queryList);