Bing Search API is not working
<p>I wants to fetch the bing api results but not succeeded on that. Already used many codes and samples but didnt get my answer. Please is dere any mistake in my code or not.</p>

<p>There are two files 
 1. bing.php (HTML)
 2. bing_code.php (PHP)</p>

<pre><code>&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Bing Search Tester (Basic)&lt;/title&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Bing Search Tester (Basic)&lt;/h1&gt;
&lt;form method="POST" action="bing_code.php"&gt;
&lt;label for="service_op"&gt;Service Operation&lt;/label&gt;&lt;br/&gt;
&lt;input name="service_op" type="radio" value="Web" CHECKED /&gt; Web
&lt;input name="service_op" type="radio" value="Image" /&gt; Image &lt;br/&gt;
&lt;label for="query"&gt;Query&lt;/label&gt;&lt;br/&gt;
&lt;input name="query" type="text" size="60" maxlength="60" value="" /&gt;&lt;br /&gt;&lt;br /&gt;
&lt;input name="bt_search" type="submit" value="Search" /&gt;
&lt;/form&gt; &lt;h2&gt;Results&lt;/h2&gt;

&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>Above is the html code
below is php code</p>

<pre><code>&lt;?php

$acctKey = 'key';

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

$contents = file_get_contents('bing.php');

if ($_POST['query'])
{

$query = urlencode("'{$_POST['query']}'");

$serviceOp = $_POST['service_op'];

$requestUri = "$rootUri/$serviceOp?\$format=json&amp;Query=$query";

$auth = base64_encode("$acctKey:$acctKey");

$data = array('http' =&gt; array('request_fulluri' =&gt; true,'ignore_errors' =&gt; true,'header' =&gt; "Authorization: Basic $auth"));

$context = stream_context_create($data);

$response = file_get_contents($requestUri, 0, $context);

$jsonObj = json_decode($response, true);

print_r($jsonObj); echo "nothing!"; die();

$resultStr = '';
if( ( is_array( $jsonObj-&gt;d-&gt;results )) &amp;&amp; ( ! empty( $jsonObj-&gt;d-&gt;results ) ) ) {
    foreach($jsonObj-&gt;d-&gt;results as $value)
    {
        switch ($value-&gt;__metadata-&gt;type)
        {
            case 'WebResult':
            $resultStr .= "&lt;a href=\"$value-&gt;Url\"&gt;{$value-&gt;Title}&lt;/a&gt;&lt;p&gt;{$value-&gt;Description}&lt;/p&gt;";
            break;
            case 'ImageResult': $resultStr .= "&lt;h4&gt;{$value-&gt;Title} ({$value-&gt;Width}x{$value-&gt;Height}) " . "{$value-&gt;FileSize} bytes)&lt;/h4&gt;" . "&lt;a href=\"{$value-&gt;MediaUrl}\"&gt;" . "&lt;img src=\"{$value-&gt;Thumbnail-&gt;MediaUrl}\"&gt;&lt;/a&gt;&lt;br /&gt;";
            break;
        }
    }
} else {
    if( ! is_array( $jsonObj-&gt;d-&gt;results )) {

        echo "jsonObj-&gt;d-&gt;results is not an array!";

    } elseif( empty( $jsonObj-&gt;d-&gt;results )) {

        echo "jsonObj-&gt;d-&gt;results is empty!";

    }
}

$contents = str_replace('{RESULTS}', $resultStr, $contents);

}

echo $contents;

?&gt;
</code></pre>