I am trying to build a web site where a user can enter their web site and check their indexed pages in Google.
Just like we do by site:domain.com.
I am using a Google API, here is the link to API (I know it’s deprecated):
http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=
When I use a code like:
<?php
function getGoogleCount($domain) {
$content = file_get_contents('http://ajax.googleapis.com/ajax/services/' .
'search/web?v=1.0&filter=0&q=site:' . urlencode($domain));
$data = json_decode($content);
return ($data->responseData->cursor->estimatedResultCount);
}
echo getGoogleCount('stackoverflow.com');
?>
It is good as far as I want to know about the result counts,
but the next thing I want is to list all the results on my we bsite. I am unable to grab the results because when we write:
$data->responseData->cursor->estimatedResultCount
It goes straight,
but when we try to get results. I don’t know how to do it, just to print the idea:
$data->responseData->results->[url & title & content here]
Because here results is an array, and I don’t know how can I store info in an array in this case.
Have been searching for a long time but can’t find anything related…..
The easiest way is to use:
That will convert objects to normal associative arrays which are probably easier to handle.
Then you access your values by something like this:
Then with the results you can do something like this:
But of course if you don’t like associative arrays and you prefer objects, you could do it also this way:
If you want to check which properties has the $result, just use
print_rorvar_dump.