(double) str_replace(',', '.', $node->getAttribute('data-qty'))$dom = new DomDocument();
@$dom->loadHTML($stok);
$xpath = new DOMXpath($dom);
$nodes = $xpath->query("//ul[@class='radio-list']//li//input");
$array = array();
foreach ($nodes as $node) {
array_push($array, array(
'label' => $node->nextSibling->nodeValue,
'name' => $node->getAttribute('name'),
'value' => $node->getAttribute('value')
));
}
exit(json_encode($array));
Alternatif;
header('Content-type: application/json');
$buffer = file_get_contents('link');
$buffer = str_replace(array("\t", "\r", "\n"), '', $buffer);
$buffer = str_replace('> <', '><', $buffer);
$buffer = str_replace(' ', '', $buffer);
$buffer = str_replace('> <', '><', $buffer);
$buffer = str_replace("\" />", "\"/>", $buffer);
// Ürün Kategori
preg_match('#<span itemprop="name">(.+?)</span>#si', $buffer, $match);
$category = $match[1];
// Ürün Adı
preg_match('#<h1 itemprop="name">(.+?)</h1>#si', $buffer, $match);
$title = $match[1];
// Ürün Açıklama
$description = explode('<div class="accordion-item accordion-fulldescription active"><div class="full-description" itemprop="description">', $buffer);
$description = explode('</div><span class="accordion-title" data-target="accordion-reviews">Yorumlar</span>', $description[1]);
$description = $description[0];
// Ürün Fotoğrafları
$swiper = explode('<div class="swiper-master gallery-thumbs"><div class="swiper-wrapper">', $buffer);
$swiper = explode('</div><div class="swiper-master gallery-top">', $swiper[1]);
$swiper = $swiper[0];
$images = array();
preg_match_all('#<img itemprop="image" src="(.+?)" alt="(.+?)" title="(.+?)"/>#si', $swiper, $matches);
foreach ($matches[1] as $index => $src) {
array_push($images, array(
'src' => $src,
'alt' => $matches[2][$index],
'title' => $matches[3][$index]
));
}
// Beden Tablosu
$sizes = explode('<ul class="radio-list">', $buffer);
$sizes = explode('</ul>', $sizes[1]);
$sizes = $sizes[0];
$sizes = trim(str_replace("</li>", "</li>\n", $sizes));
$array = array();
foreach (explode("\n", $sizes) as $node) {
$beden = $adet = NULL;
preg_match('/data-qty="([0-9]+),0000"/i', $node, $match);
$adet = $match[1];
preg_match('/<label for="(.+?)">(.+?)<\/label>/i', $node, $match);
$beden = $match[2];
array_push($array, array(
'beden' => $beden,
'adet' => $adet
));
}
// Yapısal Veri
$data = array(
'title' => $title,
'description' => $description,
'images' => $images,
'category' => $category,
'size' => $array
);