This project is read-only.

Welcome! This is the Bing SDK for PHP, a toolkit that allows you to
easily use Bing's API to fetch search results and use in your own application.

A complete class hierarchy and reference is available in the docs directory
in HTML format

Directory Structure

The following directories are included in the library:

- Msft
Contains the actual source for the SDK

- docs
Contains the autogenerated HTML reference for the SDK's classes

- tests
Contains the unit tests for the SDK

Class Inclusion

In order to use the SDK in your project, you need to include the following files:

- Msft/Exception.php
- Msft/Bing/Exception.php
- Msft/Bing/Search/Exception.php
- Msft/Bing/Search.php


Code Example 1
$o = new MsftBingSearch($myBingAPPID);

$raw = $o->search();
$result = json_decode($raw);
foreach($result->SearchResponse->Web->Results as $value) {
printf('<a href="%s">%s</a><br />',$value->Url,$value->Title);

The Bing SDK for PHP is designed to give PHP developers an object-oriented interface to access the Bing API.

The Bing SDK supports fluent interfaces in PHP so that options can be easily chained together for readability.

The heart of the SDK is the MsftBingSearch class. It supports all of the options available for searching web and images that are defined in the API.

The API docs give complete details on the methods and parameters.

As you can see from the example above, using the SDK is as simple as instantiating the class, setting the required parameters and calling the search() method. Because most parameters have logical defaults, the only required parameter is the query to execute.

Code Example 2
$o = new MsftBingSearch($myBingAPPID);
$raw = $o->search();

Code Example 2 demonstrates the minimum required to execute a search query.

The other required parameter, passed into the constructor, is your Bing APP ID. Each application with which you use the SDK will need its own APP ID. You can get your APP ID from Microsoft by going to the web page

Once you have it, store it in your confirugation file somewhere and use it everytime you connect to the Bing API.

There is one extra feature in the SDK that is not in the API itself.

First, you have the option of limiting the search to a specific site. You can do this of course by simply starting your query with "site:". However, an easier way to do it is to use the setSite('') and let the SDK do it for you.

Last edited May 25, 2010 at 1:22 AM by suchawla, version 2


halukunal Jun 19, 2012 at 2:04 PM 
@lovetocode , its true; class name diffirent and i use Msft_Bing_Search but system says my appid is invalid. I buy bing search api on windows azure marketplace. What .the problem? Can you help me !

kumarldh May 24, 2011 at 6:44 AM 
The code results in a notice being displayed. "Notice: Undefined variable: returnValue in /home/kumar/sandbox/BingPHP/lib/Msft/Bing/Search.php on line 738", the fix is easy, define a variable $returnValue on line 734 in file lib/Msft/Bing/Search.php

lovetocode Mar 1, 2011 at 6:30 AM 
$o = new MsftBingSearch($myBingAPPID); should be $o = new Msft_Bing_Search($myBingAPPID); as I discovered in the Search,php file.

SleepingTroll Jul 27, 2010 at 4:00 PM 
It does not work and the include paths given do not exist!
- Msft/Exception.php
- Msft/Bing/Exception.php
- Msft/Bing/Search.php