时时商务社区
标题:
PHP访问Google Search API的方法
[打印本页]
作者:
yj1281
时间:
2018-2-14 05:48
本文实例讲述了PHP访问Google Search API的方法。分享给大家供大家参考。具体如下:
这段代码段演示了如何从php向AJAX搜索API发送请求。请注意,此示例假定使用 PHP 5.2。对于较早安装的 PHP,请参考对应的
官方注释
。
具体代码如下:
[U]复制代码[/U] 代码如下
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程序设计有所帮助。
您可能感兴趣的文章:
用PHP获取Google AJAX Search API 数据的代码
php实现查询百度google收录情况(示例代码)
php获取域名的google收录示例
php调用google接口生成二维码示例
php使用google地图应用实例
PHP实现抓取Google IP并自动修改hosts文件
php获取Google机器人访问足迹的方法
欢迎光临 时时商务社区 (http://bbs.4435.cn/)
Powered by Discuz! X3.2