public function parse($rest_id) { $data['dishes'] = $this->_model->get_dishes($rest_id); if (empty($data['dishes'])) { libxml_use_internal_errors(true); $url = "https://www.10bis.co.il/Restaurants/Menu/Delivery/{$rest_id}"; $content = Curl::get($url); @($doc = new \DOMDocument()); @$doc->loadHTML($content); @($xml = simplexml_import_dom($doc)); // just to make xpath more simple @($dishes = $xml->xpath("//div[@data-dishid]")); foreach ($dishes as $dish) { @($dish_id = $dish['data-dishid']); @($dish_title = $dish->div[1]->div->p ?: $dish->div->div->p); @($dish_price = $dish->div[1]->div[1] ?: $dish->div->div[1]); @($dish_price = floatval(str_replace('₪', '', $dish_price))); @($dish_image = $dish->div['style']); //TODO: parse this :/ @($dish_desc = $dish['title']); @($dish_image = str_replace(array('background: url(', ') no-repeat center;'), '', $dish_image)); if (!$dish_price) { continue; } $dish_data = array('dish_id' => $dish_id, 'rest_id' => $rest_id, 'dish_price' => $dish_price, 'dish_image' => $dish_image ?: '', 'dish_title' => trim($dish_title) ?: '', 'dish_desc' => trim($dish_desc) ?: ''); $this->_model->add_dish($dish_data); } } }