《PHP應用:PHP訪問Google Search API的方法》要點:
本文介紹了PHP應用:PHP訪問Google Search API的方法,希望對您有用。如果有疑問,可以聯系我們。
PHP應用本文實例講述了PHP拜訪Google Search API的方法.分享給大家供大家參考.具體如下:
PHP應用這段代碼段演示了如何從php向AJAX搜索API發送哀求.請注意,此示例假定使用 PHP 5.2.對于較早安裝的 PHP,請參考對應的官方注釋.
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應用希望本文所述對大家的php程序設計有所贊助.
《PHP應用:PHP訪問Google Search API的方法》是否對您有啟發,歡迎查看更多與《PHP應用:PHP訪問Google Search API的方法》相關教程,學精學透。維易PHP學院為您提供精彩教程。
轉載請注明本頁網址:
http://www.snjht.com/jiaocheng/11873.html