<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Google Resim</title>
</head>
<?php
function dosyaIndir($url,$inecekDizin,$name){
$urlBilgisi = pathinfo($url);
$uzanti = strtolower($urlBilgisi['extension']);
$ism=$inecekDizin."/fmd_".$name."_".rand(1000,9999).".$uzanti";
$ch = curl_init($url);
$fopen = fopen($ism,'w');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FILE, $fopen);
curl_exec($ch);
curl_close($ch);
fclose($fopen);
return $ism; }
function al($l){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "$l");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // Allow redirection
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$a=curl_exec($ch);
curl_close($ch);
return $a; }
// Başlangıç
//https://ajax.googleapis.com/ajax/services/search/images?v=1.0&q=resim&start=2&rsz=8
if(isset($_POST["kelime"]))
{
$kelime = ($_POST["kelime"]);
$kelime2 = str_replace(" ","+", $kelime);
$sayfa = ($_POST["sayfa"]);
$sayi = $sayfa*8;
$sayi2 = $sayi+8;
;
$url = "http://ajax.googleapis.com/ajax/services/search/images?v=1.0&q=$kelime2&start=$sayi&rsz=8";
$url2 = "http://ajax.googleapis.com/ajax/services/search/images?v=1.0&q=$kelime2&start=$sayi2&rsz=8";
echo "<form method=post >
Kelime : <input type=text name=kelime value='$kelime'>
Sayfa : <input type=text name=sayfa value='$sayfa' size='1' >
<input type=submit value='Ara' name=arama ><br>
</form><br>";
$a = al($url);
$aa = al($url2);
$b = explode("Gimage" ,$a);
$bb = explode("Gimage", $aa);
//echo "<pre>";
//print_r($b);
$s = 1;
$ss = 9;
foreach($b as $c=>$d){
if($c>0){
$e=explode("\",\"title",$d);
$f=explode("\"visibleUrl\":\"",$e[0]);
$nerden=$f[1];
$e=explode("\",\"url",$d);
$f=explode("\"unescapedUrl\":\"",$e[0]);
$resimUrl = $f[1];
echo $s++." - $resimUrl <br>";
// echo "<br> Kaynak : http://$nerden<br>";
}
}
foreach($bb as $c=>$d){
if($c>0){
$e=explode("\",\"title",$d);
$f=explode("\"visibleUrl\":\"",$e[0]);
$nerden=$f[1];
$e=explode("\",\"url",$d);
$f=explode("\"unescapedUrl\":\"",$e[0]);
$resimUrl = $f[1];
echo $ss++." - $resimUrl <br>";
// echo "<br> Kaynak : http://$nerden<br>";
}
}
}
else
echo "
<form method=post >
Kelime : <input type=text name=kelime>
Sayfa : <input type=text name=sayfa value='0' size='1' >
<input type=submit value='Ara' name=arama ><br>
</form>
";
?>2 kere al fonksiyonunu kullanarak 2 farklı sayfayı çekiyorum.
2 kere foreach yazmaktansa, hem 1 de hem 2. çektiğimde aynı işlemi yapmasını sağlayabilir miyim ?
not : google images api sistemi tek seferde 8 tane foto veriyor. ben bunu 16 ya çıkarmak istiyorum.