


Develop your own search engine using Yahoo! Search API - PHP version_PHP tutorial
美国东部时间3月1日,雅虎公司联合创始人之一的杨致远将宣布公司的搜索网络将进入Web服务。雅虎公司在www.developer.yahoo.com网站建立了Yahoo Search Developer Network,公司计划在此纽约举行的搜索引擎战略大会(Search Engine Strategies Conference)上推出这一计划。该网络将允许开发者在雅虎搜索之上建立新的应用程序,其中包括图像、视频、新闻以及地区搜索等内容。想要使用这项服务的会员必须先去http://api.search.yahoo.com/webservices/register_application 申请一个自已的ID号,注:每个ID号每天只能搜索5000次。
下面我们看一下,如何用PHP脚本调用Yahoo! Search API实现搜索的效果,全部脚本如下:
// 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');
?>
function done() {?>
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 = '?query='.rawurlencode($_REQUEST['query']);
if(!empty($_REQUEST['zip'])) $q.="&zip=".$_REQUEST['zip'];
if(!empty($_REQUEST['start'])) $q.="&start=".$_REQUEST['start'];
$q .= "&appid=$appid";
// Then send it to the appropriate service
$xml = file_get_contents($service[$_REQUEST['type']].$q);
// Parse the XML and check it for errors
if (!$dom = domxml_open_mem($xml,DOMXML_LOAD_PARSING,$error)) {
echo "XML parse error\n";
foreach ($error as $errorline) {
/* For production use this should obviously be logged to a file instead */
echo $errorline['errormessage']."
\n";
echo " Node : " . $errorline['nodename'] . "
\n";
echo " Line : " . $errorline['line'] . "
\n";
echo " Column : " . $errorline['col'] . "
\n";
}
done();
}
// Now traverse the DOM with this function
// It is basically a generic parser that turns limited XML into a PHP array
// with only a couple of hardcoded tags which are common across all the
// result xml from the web services
function xml_to_result($dom) {
$root = $dom->document_element();
$res['totalResultsAvailable'] = $root->get_attribute('totalResultsAvailable');
$res['totalResultsReturned'] = $root->get_attribute('totalResultsReturned');
$res['firstResultPosition'] = $root->get_attribute('firstResultPosition');
$node = $root->first_child();
$i = 0;
while($node) {
switch($node->tagname) {
case 'Result':
$subnode = $node->first_child();
while($subnode) {
$subnodes = $subnode->child_nodes();
if(!empty($subnodes)) foreach($subnodes as $k=>$n) {
if(empty($n->tagname)) $res[$i][$subnode->tagname] = trim($n->get_content());
else $res[$i][$subnode->tagname][$n->tagname]=trim($n->get_content());
}
$subnode = $subnode->next_sibling();
}
break;
default:
$res[$node->tagname] = trim($node->get_content());
$i--;
break;
}
$i++;
$node = $node->next_sibling();
}
return $res;
}
$res = xml_to_result($dom);
// 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 "
Matched ${res[totalResultsAvailable]}, showing $first to $last
\n";if(!empty($res['ResultSetMapUrl'])) {
echo "
Result Set Map: ${res[ResultSetMapUrl]}
\n";}
for($i=0; $i<$res['totalResultsReturned']; $i++) {
foreach($res[$i] as $key=>$value) {
switch($key) {
case 'Thumbnail':
echo "
break;
case 'Cache':
echo "Cache: ${value[Url]} [${value[Size]}]
\n";
break;
case 'PublishDate':
echo "$key: ".strftime('%X %x',$value);
break;
default:
if(stristr($key,'url')) echo "$value
\n";
else echo "$key: $value
";
break;
}
}
echo "
\n";
}
// Create Previous/Next Page links
if($start > 1)
echo '<-Previous Page ';
if($last < $res['totalResultsAvailable'])
echo 'Next Page->';
done();
?>
有兴趣的朋友还可以看一下由[动态网站制作指南]所制作的ASP版本:http://www.knowsky.com/yahoo/

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

This AI-assisted programming tool has unearthed a large number of useful AI-assisted programming tools in this stage of rapid AI development. AI-assisted programming tools can improve development efficiency, improve code quality, and reduce bug rates. They are important assistants in the modern software development process. Today Dayao will share with you 4 AI-assisted programming tools (and all support C# language). I hope it will be helpful to everyone. https://github.com/YSGStudyHards/DotNetGuide1.GitHubCopilotGitHubCopilot is an AI coding assistant that helps you write code faster and with less effort, so you can focus more on problem solving and collaboration. Git

Xiaohongshu, a platform full of life and knowledge sharing, allows more and more creators to express their opinions freely. In order to get more attention and likes on Xiaohongshu, in addition to the quality of content, the time of publishing works is also crucial. So, how to set the time for Xiaohongshu to publish works? 1. How to set the time for publishing works on Xiaohongshu? 1. Understand the active time of users. First, it is necessary to clarify the active time of Xiaohongshu users. Generally speaking, 8 pm to 10 pm and weekend afternoons are the times when user activity is high. However, this time period will also vary depending on factors such as audience group and geography. Therefore, in order to better grasp the active period of users, it is recommended to conduct a more detailed analysis of the behavioral habits of different groups. By understanding users’ lives

On March 3, 2022, less than a month after the birth of the world's first AI programmer Devin, the NLP team of Princeton University developed an open source AI programmer SWE-agent. It leverages the GPT-4 model to automatically resolve issues in GitHub repositories. SWE-agent's performance on the SWE-bench test set is similar to Devin, taking an average of 93 seconds and solving 12.29% of the problems. By interacting with a dedicated terminal, SWE-agent can open and search file contents, use automatic syntax checking, edit specific lines, and write and execute tests. (Note: The above content is a slight adjustment of the original content, but the key information in the original text is retained and does not exceed the specified word limit.) SWE-A

Go language development mobile application tutorial As the mobile application market continues to boom, more and more developers are beginning to explore how to use Go language to develop mobile applications. As a simple and efficient programming language, Go language has also shown strong potential in mobile application development. This article will introduce in detail how to use Go language to develop mobile applications, and attach specific code examples to help readers get started quickly and start developing their own mobile applications. 1. Preparation Before starting, we need to prepare the development environment and tools. head

Blue Star Travel Ballad has been on the game hot list after the recent release of a promotional video. Many players are very curious about which company Blue Star Travel Ballad is made from. In fact, it is a new game from Shanghai 2D manufacturer Manjiu. The editor will explain it to you below. Here is the introduction of Blue Star Yuanluyao Game Company, come and take a look together. Which company does Blue Star Travel Yao come from? Answer: It was launched by Manjiu Network. 1. First of all, Blue Star Travel Yao is a game launched by Manju’s Big World RPG. A promotional video was released on March 20. 2. This product will get its version number in October 2023. The game's trademark and operating unit are both registered under the name of a company called. The latter was established in February 2023, and its official website shows that its headquarters is in Singapore. 3. The 11-minute promotional video released this time revealed this

According to news from this website on April 10, according to the Liberty Times, TSMC plans to send Dr. Zhuang Zishou to the United States in May this year to cooperate with Wang Yinglang to jointly promote the construction of TSMC’s US factory. The U.S. Department of Commerce has currently finalized the amount of subsidies for TSMC, Intel, and Samsung, but TSMC's factories in the United States still have many problems. TSMC’s leadership hopes to promote the implementation of advanced processes as soon as possible by sending Dr. Zhuang Zishou to work with Wang Yinglang, who specializes in production and manufacturing. Check out the official TSMC leadership team on this site: Dr. Zhuang Zishou is currently the deputy general manager of factory affairs at TSMC, responsible for the planning, design, construction and maintenance of new factories, as well as the operation and upgrade of existing factory facilities. Dr. Zhuang joined TSMC in 1989 as a

"Understanding VSCode: What is this tool used for?" 》As a programmer, whether you are a beginner or an experienced developer, you cannot do without the use of code editing tools. Among many editing tools, Visual Studio Code (VSCode for short) is very popular among developers as an open source, lightweight, and powerful code editor. So, what exactly is VSCode used for? This article will delve into the functions and uses of VSCode and provide specific code examples to help readers

PHP belongs to the backend in web development. PHP is a server-side scripting language, mainly used to process server-side logic and generate dynamic web content. Compared with front-end technology, PHP is more used for back-end operations such as interacting with databases, processing user requests, and generating page content. Next, specific code examples will be used to illustrate the application of PHP in back-end development. First, let's look at a simple PHP code example for connecting to a database and querying data:
