5

Search on Google images with car keyword & get car images.

enter image description here

I found two links to implement like this,

  1. PHP class to retrieve multiple images from Google using curl multi handler
  2. Google image API using cURL

implement also but it gave 4 random images not more than that. enter image description hereenter image description hereenter image description hereenter image description here

Question: How to get car images in PHP using keyword i want to implement like we search on Google?

Any suggestion will be appreciated!!!

Kara
  • 6,115
  • 16
  • 50
  • 57
Tony Stark
  • 8,064
  • 8
  • 44
  • 63
  • 1
    The link you posted in your question has a note at the bottom stating that if you want more than 4 images try this: http://webcodingeasy.com/PHP-classes/PHP-class-to-retrieve-multiple-images-from-Google-using-curl-multi-handler – shannonman May 09 '13 at 08:39
  • @shannonman yes when i open this link my first link open & give same results & i also change $count value but get same. – Tony Stark May 09 '13 at 08:58

2 Answers2

6

You could use the PHP Simple HTML DOM library for this:

<?php
    include "simple_html_dom.php";
    $search_query = "ENTER YOUR SEARCH QUERY HERE";
    $search_query = urlencode( $search_query );
    $html = file_get_html( "https://www.google.com/search?q=$search_query&tbm=isch" );
    $image_container = $html->find('div#rcnt', 0);
    $images = $image_container->find('img');
    $image_count = 10; //Enter the amount of images to be shown
    $i = 0;
    foreach($images as $image){
        if($i == $image_count) break;
        $i++;
        // DO with the image whatever you want here (the image element is '$image'):
        echo $image;
    }

This will print a specific number of images (number is set in '$image_count').

For more information on the PHP Simple HTML DOM library click here.

0

i am not very much sure about this ,but still google gives a nice documentation about this.

 $url = "https://ajax.googleapis.com/ajax/services/search/images?" .
   "v=1.0&q=barack%20obama&userip=INSERT-USER-IP";   
// sendRequest
// note how referer is set manually
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, /* Enter the URL of your site here */);
$body = curl_exec($ch);
curl_close($ch);

// now, process the JSON string
$json = json_decode($body);
// now have some fun with the results...

this is from the official Google's developer guide regarding image searching. for more reference you can have a reference of the same here.

 https://developers.google.com/image-search/v1/jsondevguide#json_snippets_php

in $url you must set the search keywords.