<?php ## by 6epcepk // set_time_limit(0); $data = array( array( 'title' => 'Logitech Revolution', 'price' => '3000' ), array( 'title' => 'Logitech MX500', 'price' => '1500' ), array( 'title' => 'Nokia N93', 'price' => '15 000' ), array( 'title' => 'Nokia 7610', 'price' => '13 000' ), array( 'title' => 'Novex NCD-103', 'price' => '34 000' ), array( 'title' => 'Akai E304', 'price' => '25 000' ) ); echo '<table>'; echo '<tr>'; echo '<td>Title</td>'; echo '<td>Price</td>'; echo '<td>Image</td>'; echo '</tr>'; foreach ($data as $value) { echo '<tr>'; echo '<td>' . $value['title'] . '</td>'; echo '<td>' . $value['price'] . '</td>'; echo '<td><a href="' . get_search_results($value['title']) . '" target="_blank">See image</a></td>'; echo '</tr>'; } echo '</table>'; function get_search_results($search_str = '') { $search_str = str_replace(' ', '+', $search_str); $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, 'http://market.yandex.ru/search.xml?cvredirect=1&text=' . $search_str); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_HEADER, 1); $html = curl_exec($curl); curl_close($curl); return get_search_results_page($html); } function get_search_results_page($html) { preg_match('#hid=([0-9]+)&modelid=([0-9]+)(.*)#', $html, $matches); if (empty($matches[1])) preg_match('#hid=([0-9]+)&modelid=([0-9]+)(.*)#', $html, $matches); if (!empty($matches[1])) { $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, 'http://market.yandex.ru/model.xml?hid=' . $matches[1] . '&modelid=' . $matches[2]); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $html = curl_exec($curl); curl_close($curl); return get_image($html); } else { return get_image($html); } } function get_image($html) { preg_match('#i?ctype=1&path=(.*?)"#', $html, $matches); if (!empty($matches[1])) { return 'http://data.yandex.ru/i?ctype=1&path=' . $matches[1]; } else { return false; } } ?> <style type="text/css"> table { border-collapse: collapse; margin-top: 10px; } table td { border: 1px solid #d3d4d5; padding: 3px 5px; width: 25%; } table td.header { border: 1px solid #d3d4d5; padding: 3px 5px; width: 25%; background: #eae8e8; } table td.category { border: 1px solid #d3d4d5; padding: 3px 5px; background: #f4f3f3; } table td.category a { color: #808080; } table tr:hover { background: #f2f5fd; } a { color: #224db3; text-decoration: none; } a:hover { color: #0536ab; background: #e5ecfe; text-decoration: underline; } </style> |