<html>
<head>
<title>Test</title>
</head>
<body>
<center>
<form action="" method="GET">
<input type="text" name="search" size="30" value="
<?PHP isset($_GET ['search']) ?
$_GET ['search'] : '' ; ?>">
<input type="submit" value="Поиск">
</form>
</center>
<p>
<?PHP
if (!empty($_GET ['search'])) {
//Кол-во рисунков на странице
$per_page = 18;
//Текущая страница
$current_page = (!empty($_GET ['page'])) ?
(int
)$_GET['page'] : 1; //Номера начальной и конечной страниц
$start_page = $current_page*$per_page-($per_page - 1);
$end_page = $current_page*$per_page;
//Поисковая фраза
//Апорт
/*Содержимое первой страницы*/
//$aport_site = file_get_contents('http://sm.aport.ru/scripts/template.dll?That=pics&flt=f00&r=' .$search);
/*Содержимое второй страницы*/
$aport_site = file_get_contents('http://sm.aport.ru/scripts/template.dll?That=pics&flt=f00&p=1&r=' .$search); /*Регулярное выражение для поиска ссылок*/
$pattern = '~a href="(http://[^\s"\']{10,})"\s+target=_blank>[\s\n]*<img src="(http://img.aport.ru/docstorage.dll\?base=[0-9]+&id=[0-9]{3,})~';
/*Масив предварительного просмотра*/
$aport_img_small = $aport_imgs[2];
/*Масив оригинальных изображений*/
$aport_img_big = $aport_imgs[1];
/*Google*/
/*Первая страница*/
//$google_site = file_get_contents('http://images.google.com/images?gbv=2&svnum=10&hl=ru&q='.$search);
/*Вторая страница*/
$google_site = file_get_contents('http://images.google.com/images?gbv=2&svnum=20&hl=ru&start=21&sa=N&q='.$search); /*Шаблон для полученич рисунков*/
$pattern = '~,"([-_A-z0-9]+?):","(http://.+?)",~';
/*Занесение рисунков в отдельный масив*/
$google_img_small = $google_imgs[1];
$google_img_big = $google_imgs[2];
/*Формирование ссылки для рисунков предпросмотра*/
for ($i = 0; $i < count($google_img_small); $i++) {
$google_img_small[$i] = 'http://tbn0.google.com/images?q=tbn:'.$google_img_small[$i];
}
/*проверка результатов Google*/
$google_img_small = array(); /*Проверка результатов Апорт*/
$aport_img_small = array(); /*Склеивание массивов со ссылками на предварительный просмотр*/
$img_small = array_merge($google_img_small, $aport_img_small); /*Склеивание массивов со ссылками на оригинальеые картинки*/
$img_big = array_merge($google_img_big, $aport_img_big); /*Убираем одинаковые ссылки*/
/*Навигация по страницам*/
if ($end_page > count($img_small)-1
) $end_page = count($img_small)-1;
$page_count = ceil( (count($img_small)-1
)/ $per_page);
echo '<hr><p align="center"><b>';
for ($i=1; $i <= $page_count; $i++)
{
echo ':' . ($current_page==$i?$i:'<a href="?search=' .$search. '&page=' .$i.'">'.$i.'</a>').':';
}
echo '</b></p><hr>';
echo '<table width="100%" align="center" border="0" valign="middle" cellspacing="20"><tr>';
$tr = 0;
/*Цикл вывода изображений*/
for ($i = $start_page; $i <= $end_page; $i++)
{
if ($tr == 6)
{
$tr = 0;
echo '</tr><tr>';
}
continue;
$tr++;
echo '<td><a href="'.$img_big[$i].'"
target="_blank"><img src="' .$img_small[$i] .'" border="0"></td>';
}
echo '</tr></table><body></html>';
}
?>