images.google.com dan sonuç resimlerini almak

0
Onaylı Üye
Üye
Katılım
30 Kasım 2006
Mesajlar
0
Tepki puanı
0
Konum
<%=istanbul%>
PHP:
<?

$results = getGoogleImages('"300 (2006)"+movie+poster');
foreach ($results as $result) {

    echo '<img src="' . htmlentities($result['image']) . '"/>';
}


function getGoogleImages($q, $doSafeSearch = false)
{
    $results = array();

    $safe = ($doSafeSearch) ? 'on' : 'off';
    $url = 'http://images.google.com/images?safe=' . $safe .
            '&q=' . urlencode($q);
    $result = file_get_contents($url);

    $from = 'dyn.Img("';
    $startPos = strPos($result, $from);
    $endPos = strPos($result, ');dyn.updateStatus');
    $functions = substr( $result, $startPos + strlen($from), $endPos );
    $functions = explode('");dyn.Img("', $functions);

    foreach ($functions as $f) {
        $i = count($results);
        list($results[$i]['url'], $v1, $hash,
                $results[$i]['image']) = explode('","', $f);
        list($results[$i]['url'], $params) = explode('&h', $results[$i]['url']);

    }

    return $results;
}

?>

Daha işlevsel bir koddu ama bana lazım olmayan kısımlarını kırptım (kod nette mevcut)
kod bu şekilde işliyor ama ihtiyacım olan sadece ilk resmi göstermesi foreach lerden kurtulmak...
 
Geri
Üst