Read Google search results in a PHP array?

In short, I'm looking for a way to do this:

$results_array = google("search terms"); // returns array of URLs

So, for example, if my search terms were "cat videos", my $ results_array [0] could be a Youtube URL, and $ results_array 1 might include Vimeo.

I have seen the Google Custom Search API, but they all require complex JSON, ATOM, REST, or some other kind of system that is too complex for what I'm trying to do.

Are there any simple solutions?

EDIT: I found it, thanks to another post

Thanks to this post, I was able to figure it out. In short, I just used the following:

$results = json_decode(file_get_contents( 
          'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q='.
           urlencode($search)));

echo $results->responseData->results[$resultNumber]->url;

downvotes - , , , . JSON, . , , :

function google($query) {
    $results = json_decode(file_get_contents( 
          'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q='.
           urlencode($search)));

    return $results->responseData->results
}
+5
1

, .

//replace space between words with +
$query = "cat+video"; 
$start = 0;
/*
this url will give you json response with 4 results each time.
u have to change the $start like 0, 4, 8,...
use json_decode() and get it in array
*/

$url = 'https://ajax.googleapis.com/ajax/services/search/video?v=1.0&q='.$query.'&start='.$start

, .

+3

All Articles