利用Yahoo! Search API开发自已的搜索引擎(2)

// Ok, now that we have the results in an easy to use format,
// display them.  It's quite ugly because I am using a single
// display loop to display every type and I don't really understand HTML
$first = $res['firstResultPosition'];
$last = $first + $res['totalResultsReturned']-1;
echo "<p>Matched ${res[totalResultsAvailable]}, showing $first to $last</p>\n";
if(!empty($res['ResultSetMapUrl'])) {
  echo "<p>Result Set Map: <a href=https://www.jb51.net/article/\"${res[ResultSetMapUrl]}\">${res[ResultSetMapUrl]}</a></p>\n";
}
for($i=0; $i<$res['totalResultsReturned']; $i++) {
  foreach($res[$i] as $key=>$value) {
    switch($key) {
      case 'Thumbnail':
        echo "<img src=https://www.jb51.net/article/\"${value[Url]}\" height=https://www.jb51.net/article/\"${value[Height]}\" width=https://www.jb51.net/article/\"${value[Width]}\" />\n";
        break;
      case 'Cache':
        echo "Cache: <a href=https://www.jb51.net/article/\"${value[Url]}\">${value[Url]}</a> [${value[Size]}]<br />\n";
        break;
      case 'PublishDate':
        echo "<b>$key:</b> ".strftime('%X %x',$value);
        break;
      default:
        if(stristr($key,'url')) echo "<a href=https://www.jb51.net/article/\"$value\">$value</a><br />\n";
        else echo "<b>$key:</b> $value<br />";
        break;
    }
  }
  echo "<hr />\n";
}

// Create Previous/Next Page links
if($start > 1)
  echo '<a href="/YahooSearchExample.php'.
                       '?query='.rawurlencode($_REQUEST['query']).
                         '&zip='.rawurlencode($_REQUEST['zip']).
                        '&type='.rawurlencode($_REQUEST['type']).
                       '&start='.($start-10).'">&lt;-Previous Page</a> &nbsp; ';
if($last < $res['totalResultsAvailable'])
  echo '<a href="/YahooSearchExample.php'.
                       '?query='.rawurlencode($_REQUEST['query']).
                         '&zip='.rawurlencode($_REQUEST['zip']).
                        '&type='.rawurlencode($_REQUEST['type']).
                       '&start='.($last+1).'">Next Page-&gt;</a>';
done();
?>

有兴趣的朋友还可以看一下由[动态网站制作指南]所制作的ASP版本:

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/62a28dc70d280562f170cb578fd4158b.html