当前位置:实例文章 » PHP实例» [文章]PHP访问Google Search API的方法

PHP访问Google Search API的方法

发布人:shili8 发布时间:2022-12-08 16:49 阅读次数:33

本文实例讲述了php访问google search api的方法。分享给大家供大家参考。具体如下:

这段代码段演示了如何从php向ajax搜索api发送请求。请注意,此示例假定使用 php 5.2。对于较早安装的 php,请参考对应的。

具体代码如下:

复制代码 代码如下:
$url = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=paris%20hilton";
?
// sendrequest
// note how referer is set manually
$ch = curl_init();
curl_setopt($ch, curlopt_url, $url);
curl_setopt($ch, curlopt_returntransfer, 1);
curl_setopt($ch, curlopt_referer, "http://www.mysite.com/index.html");
$body = curl_exec($ch);
curl_close($ch);
?
// now, process the json string
$json = json_decode($body);
// now have some fun with the results...

希望本文所述对大家的php程序设计有所帮助。

相关标签:

免责声明

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱290110527@qq.com删除。

其他信息

其他资源

Top