<?php include "GetData.php"; $object = new GetDataIkea(); $a = $object->GetData("http://www.ikea.com/ru/ru/catalog/products/10203573/"); //$a = $object->curl_get_file_contents("http://www.ikea.com/ru/ru/catalog/products/10203573/"); echo $a;
function DisplayInfo($url) { $object = new GetDataIkea(); $info = $object->GetData($url); return $info; }
function GetData($SendUrl) { $newtypes = false; $data = $SendUrl; if (substr($data, 0, 34) == "http://www.ikea.com/ru/ru/catalog/") { if (preg_match("/\\w\\d{8}/", $data, $match, PREG_OFFSET_CAPTURE) == 1) { $url = "http://www.ikea.com/ru/ru/catalog/products/" . $match[0][0] . "/"; $url2 = "http://www.ikea.com/ru/ru/catalog/products/" . $match[0][0] . "/"; } elseif (preg_match("/\\d{8}/", $data, $match, PREG_OFFSET_CAPTURE) == 1) { $url = "http://www.ikea.com/ru/ru/catalog/products/" . $match[0][0] . "/"; $url2 = FALSE; } } else { $url = ""; } $content = $this->curl_get_file_contents($url); if ($url2) { $url = $url2; $content = $this->curl_get_file_contents($url); $newtypes = true; } if ($content) { $pre = preg_match("/jProductData = (.*)\\};/i", $content, $matches); $json = json_decode($matches[1] . "}"); $pre = preg_match_all("/[0-9]{8}/", $url, $matches); $temporaryMatch = preg_match('#<ul id="breadCrumbs">(.+?)</ul>#is', $content, $hmatches); $categoryHtml = $hmatches[0]; $html = str_get_html($categoryHtml); $e = $html->find("ul", 0); $CatArray = explode("/", preg_replace("/\\s{2,}/", "", $e->plaintext)); if (count($matches[0]) == 2) { $sku = $matches[0][1]; } else { $sku = $matches[0][0]; } if ($newtypes) { $sku = "S" . $sku; } foreach ($json->product->items as $titem) { if ($titem->partNumber == $sku) { $item = $titem; } } $name = $item->name; //var_dump($item); $Category = $CatArray; $price = $item->prices->normal->priceNormal->rawPrice; $partnumber = $item->partNumber; $images = $item->images->zoom; $arrParmOfName[] = $item->type; $arrParmOfName[] = $item->validDesign; $conName = GetDataIkea::checkExist($name, $arrParmOfName); $arrParmOfDescription[] = isset($item->custBenefit) ? $item->custBenefit : " "; $arrParmOfDescription[] = isset($item->careInst) ? $item->careInst : " "; $arrParmOfDescription[] = isset($item->custMaterials) ? $item->custMaterials : " "; $connDescription = GetDataIkea::checkExist("ОПИСАНИЕ: ", $arrParmOfDescription); if ($name && $price) { $sData = array("name" => $conName, "category" => $Category, "decription" => $connDescription, "partnumber" => $partnumber, "price" => $price, "images" => $images); unset($content); return $sData; } else { unset($content); return false; } } else { unset($content); return false; } }