当前位置:编程学习 > php >>

利用Yahoo! Search API开发自已的搜索引擎-php版




<?php
// Yahoo Web Services PHP Example Code
// Rasmus Lerdorf
// www.knowsky.com

$appid = ''YahooDemo'';
// 在这输入你申请的ID号

$service = array(''image''=>''http://api.search.yahoo.com/ImageSearchService/V1/imageSearch'',
                 ''local''=>''http://api.local.yahoo.com/LocalSearchService/V1/localSearch'',
                 ''news''=>''http://api.search.yahoo.com/NewsSearchService/V1/newsSearch'',
                 ''video''=>''http://api.search.yahoo.com/VideoSearchService/V1/videoSearch'',
                 ''web''=>''http://api.search.yahoo.com/WebSearchService/V1/webSearch'');
?>
<html>
<head><title>PHP Yahoo Web Service Example Code</title></head>
<body>
<form action="YahooSearchExample.php" method="GET">
Search Term: <input type="text" name="query" /><br />
Zip Code: <input type="text" name="zip" /> (for local search)<br />
<input type="submit" value=" Go! " />
<select name="type">
<?php foreach($service as $name => $val) {
    if(!empty($_REQUEST[''type'']) && $name == $_REQUEST[''type''])
      echo "<option SELECTED>$name</option>n";
    else echo "<option>$name</option>n";
} ?>
</select>
</form>
<?php
function done() {?>
</body></html>
<?php
exit;
}

if(empty($_REQUEST[''query'']) || !in_array($_REQUEST[''type''],array_keys($service))) done();

// Ok, here we go, we have the query and the type of search is valid
// First build the query
$q = '
补充:Php教程,Php常用代码
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,