<?php
$query = 'Nikita%20Platonenko';
$url = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=".$query;
$body = file_get_contents($url);
$json = json_decode($body);
for($x=0;$x<count($json->responseData->results);$x++){
echo "<b>Result ".($x+1)."</b>";
echo "<br>URL: ";
echo $json->responseData->results[$x]->url;
echo "<br>VisibleURL: ";
echo $json->responseData->results[$x]->visibleUrl;
echo "<br>Title: ";
echo $json->responseData->results[$x]->title;
echo "<br>Content: ";
echo $json->responseData->results[$x]->content;
echo "<br><br>";
}
?>
由于 AJAX Api 现在已贬值,您可以使用SerpApi等第三方服务来获取 Google 结果。他们有一个GitHub存储库,应该很容易集成:
$query = [
"q" => "Coffee",
"google_domain" => "google.com",
];
$serp = new GoogleSearchResults();
$json_results = $serp.json($query);