如何在PHP中的Bing搜索api中为多个页面添加页面链接

时间:2015-04-16 07:17:52

标签: php search-engine bing-api

我使用以下代码在我的网页中包含bing API。如何为此网络搜索添加分页?

目前它仅显示前50个结果,并且不显示其他结果的页面链接。另外,如何将一页的结果限制为20?

<?php
   if (isset($_POST['submit'])) 
   {
    $acctKey = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
    $rootUri = 'https://api.datamarket.azure.com/Bing/Search';
    $query = $_POST['searchText'];
    $serviceOp ='Web';
    $market ='en-us';
    $query = urlencode("'$query'");
    $requestUri = "$rootUri/$serviceOp?\$format=json&Query=$query";
    $auth = base64_encode("$acctKey:$acctKey");
    $data = array(  
        'http' => array(
                    'request_fulluri' => true,
                    'ignore_errors' => true,
                    'header' => "Authorization: Basic $auth"
                    )
        );
    $context = stream_context_create($data);
    $response = file_get_contents($requestUri, 0, $context);
    $response=json_decode($response);
    echo "<pre>";
    echo("<ol>");
    foreach($response->d->results as $value)
    {
    $Ur = $value->Url;
    echo '<li class="resultlistitem"><a href="{$Ur}"> '.$Ur. '
    </a><br><p>';
    echo($value->Description .'</li> </p>');

    }
    echo("</ol>"); 
    echo "</pre>";
    }

?>

0 个答案:

没有答案