PHP访问Google Search API PHP访问Google Search API的方法

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

PHP访问Google Search API PHP访问Google Search API的方法

红薯   2021-03-21 我要评论
想了解PHP访问Google Search API的方法的相关内容吗,红薯在本文为您仔细讲解PHP访问Google Search API的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:PHP,访问,Google,Search,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...

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

猜您喜欢

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们