PHP访问Google Search API的方法
更新时间:2015年03月05日 10:24:21 作者:红薯
这篇文章主要介绍了PHP访问Google Search API的方法,实例分析了php针对谷歌API访问的技巧,具有一定参考借鉴价值,需要的朋友可以参考下
本文实例讲述了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...
// 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程序设计有所帮助。
相关文章
Win2003下IIS+PHP+MySQL+Zend配置步骤详解
Win2003下IIS+PHP+MySQL+Zend配置步骤详解...2007-05-05PHP基于imagick扩展实现合成图片的两种方法【附imagick扩展下载】
这篇文章主要介绍了PHP基于imagick扩展实现合成图片的两种方法,结合实例形式分析了php使用imagick扩展进行图片合并的具体操作方法与相关实现技巧,并附带imagick扩展下载地址与配置方法,需要的朋友可以参考下2017-11-11
最新评论