The Bing Search Engine API is available for PHP developers. You can easily use it within your PHP code and perform various searches using the Bing search engine server side.
In order to use the Bing API PHP library you first need to obtain a Bing App ID. The process for getting that ID is fairly simple and starts by visiting at www.bing.com/developers/appids.aspx.
During the process of getting the Bing App ID you should fill in various details such as the domain name of the web site from which you plan to use the Bing API PHP library.
When you complete filling the details you will get the Bing APP ID. The screenshot below includes red marks that hide the Bing APP ID I received
Once you have the Bing App ID the next step would be getting the Bing API PHP library. For now, this library includes one single PHP file you should include within your PHP code. You can download it at bingapiphp.codeplex.com.
The code below shows a simple use of the Bing API PHP library that performs a simple web search for the “jacado” term. The string you should pass over to the BingAPI constructor should be the Bing APP ID you received. The Bing APP ID below is a fake one. Make sure to replace it with yours.
<?php
require_once ‘BingAPI.php’;
$search = new BingAPI(‘GFHS640411BA9FBCC911067B79D8C89CA2FCED0’);
$search->query(‘jacado’);
$search->setFormat(‘xml’);
$search->setSources(‘Web’);
echo $search->getResults();
?>
The screenshot below shows the result we get when running this PHP script at http://www.lifemichael.com/demo/bingdemo/showbing.php.
I chose to take this screenshot browsing using the Internet Explorer. Comparing with the other web browsers it does a very good job when displaying XML files.
One improvement I can think of the developers of this library might want to implement is setting more default configuration so that developers won’t even need to specify the format of the result nor the source in which they want the search to be performed.