日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

bing搜索php,PHP 使用bing搜索网站的api封装类用法

發布時間:2023/12/2 php 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 bing搜索php,PHP 使用bing搜索网站的api封装类用法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

/**

* 使用bing api搜索網站的PHP封裝類

*

* @param

* @author 編程之家 jb51.cc jb51.cc

**/

class BingAPI{

var $accountKey = '';

var $ServiceRootURL = 'https://api.datamarket.azure.com/Bing/Search/';

var $WebSearchURL;

var $searchText;

var $searchType;

var $request_data;

var $AutoGet = true;

var $ReturnType = 'JSON'; //Options: JSON,ARRAY

var $ResultsLimit = 10;

function __construct(){

}

function setQuery_Type($query,$type){

$this->searchText = $query;

switch($type){

case 'Web':$this->searchType = 'Web';break;

case 'Image':$this->searchType = 'Image';break;

case 'News':$this->searchType = 'News';break;

case 'Video':$this->searchType = 'Video';break;

case 'Related':$this->searchType = 'RelatedSearch';break;

}

$this->createURL();

}

function createURL(){

$this->WebSearchURL = $this->ServiceRootURL . $this->searchType .'?$format=json&$top='.$this->ResultsLimit.'&Query=';

$this->context = stream_context_create(array(

'http' => array(

'request_fulluri' => true,'header' => "Authorization: Basic " . base64_encode($this->accountKey . ":" . $this->accountKey)

)

));

$this->request = $this->WebSearchURL . urlencode( '\'' . $this->searchText . '\'');

if($this->AutoGet){

$this->get();

}

}

function get(){

$response = file_get_contents($this->request,$this->context);

$this->request_data = json_decode($response);

}

function decoded_data(){

$r_array = array();

switch($this->searchType){

case 'Web':

$obj = $this->request_data->d->results;

$ic = count($obj);

for($i=0;$i

$r_array[$i] = array('Title'=>$obj[$i]->Title,'Description'=>$obj[$i]->Description,'Url'=>$obj[$i]->Url);

}

break;

case 'Image':

$obj = $this->request_data->d->results;

$ic = count($obj);

for($i=0;$i

$r_array[$i] = array('Title'=>$obj[$i]->Title,'MediaURL'=>$obj[$i]->MediaUrl,'Width'=>$obj[$i]->Width,'Height'=>$obj[$i]->Height,'ContentType'=>$obj[$i]->ContentType,'Thumbnail'=>$obj[$i]->Thumbnail->MediaUrl);

}

break;

case 'News':

$obj = $this->request_data->d->results;

$ic = count($obj);

for($i=0;$i

$r_array[$i] = array('Title'=>$obj[$i]->Title,'Url'=>$obj[$i]->Url,'Source'=>$obj[$i]->Source,'Date'=>$obj[$i]->Date);

}

break;

case 'Video':

$obj = $this->request_data->d->results;

$ic = count($obj);

for($i=0;$i

$r_array[$i] = array('Title'=>$obj[$i]->Title,'MediaUrl'=>$obj[$i]->MediaUrl,'DisplayUrl'=>$obj[$i]->DisplayUrl,'Runtime'=>$obj[$i]->Runtime,'Thumbnail'=>$obj[$i]->Thumbnail->MediaUrl);

}

break;

case 'RelatedSearch':

$obj = $this->request_data->d->results;

$ic = count($obj);

for($i=0;$i

$r_array[$i] = array('Keyword'=>$obj[$i]->Title);

}

break;

}

switch($this->ReturnType){

case 'JSON':return json_encode($r_array);

case 'ARRAY':return $r_array;

}

}

}

/*** 來自編程之家 jb51.cc(jb51.cc) ***/

總結

以上是生活随笔為你收集整理的bing搜索php,PHP 使用bing搜索网站的api封装类用法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。