【发布时间】:2014-08-18 17:44:35
【问题描述】:
我正在尝试在我的网页上显示 Google 的搜索结果,但我在 Google 文档中找到的一些示例失败了。这是我到目前为止所做的 - 这没有显示任何结果。有什么想法吗?
<?php
$query = 'test';
$url = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&key=myKeyfromAPI&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>";
}
?>
【问题讨论】: