John Adawan John Adawan - 5 months ago 30
PHP Question

simple php script to retrieve google keyword search completion

I am trying to retrieve just the search completion shown in Google search result for any keyword. For example the search completion for

http://www.google.com/#hl=en&q=google+keyword+search

is 48,400,000 (Results 1 - 10 of about 48,400,000 for google keyword search)

I tried to use CURL but fail to retrieve the search result page.

Any help appreciated.

Answer

You don't need to do anything nearly that complicated.

Just use their search API

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

echo $results->responseData->cursor->estimatedResultCount;
Comments