Use Yahoo! Develop your own search engine using SearchAPI-php version

Source: Internet
Author: User
Tags parse error
& Nbsp; on February 23, March 1, Yang Zhiyuan, co-founder of Yahoo, will announce that the company's search network will enter Web services. Yahoo! has established the yahoosearchpipeline network on www.developer.yahoo.com. The company plans to hold the search engine strategy conference (Se

Yang Zhiyuan, co-founder of Yahoo!, will announce that the company's search network will enter Web services on July 15, March 1. Yahoo! has established the Yahoo Search Developer Network on www.developer.yahoo.com. The company plans to launch this plan at the Search Engine Strategies Conference held in New York. This network will allow developers to create new applications for Yahoo search, including images, videos, news, and regional searches. Members who want to use this service must first go to the http://api.search.yahoo.com/webservices/register_application to apply for a self-idnumber, note: Each idnumber can only search 5000 times a day.

Next, let's take a look at how to use php (as the mainstream development language) scripts to call Yahoo! Search by using the Search API. all scripts are as follows:

// Yahoo Web Services php (as the mainstream development language) Example Code
// Rasmus Lerdorf
// Www.acnow.net

$ Appid = YahooDemo;
// Enter your ID number here

$ Service = array (image => http://api.search.yahoo.com/ImageSearchService/V1/imageSearch,
Http://api.local.yahoo.com/LocalSearchService/V1/localSearch,
News => http://api.search.yahoo.com/NewsSearchService/V1/newsSearch,
Http://api.search.yahoo.com/VideoSearchService/V1/videoSearch,
Web => http://api.search.yahoo.com/WebSearchService/V1/webSearch );
?>

Php (as the mainstream development language) Yahoo Web Service Example Code


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 (standardization is getting closer and closer) = file_get_contents ($ service [$ _ REQUEST [type]. $ q );

// Parse the xml (standardization is getting closer and closer) and check it for errors
If (! $ Dom = domxml (standardization is getting closer and closer) _ open_mem ($ xml (standardization is getting closer and closer), DOMxml (standardization is getting closer and closer) _ LOAD_PARSING, $ error )){
Echo "xml (standardization is getting closer and closer) parse error ";
Foreach ($ error as $ errorline ){
/* For production use this shocould obviusly be logged to a file instead */

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.