PHP
  Home arrow PHP arrow Page 2 - Implementing Yahoo Image Search Web Se...
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
eWeek
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Implementing Yahoo Image Search Web Service with PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 3
    2008-01-29

    Table of Contents:
  • Implementing Yahoo Image Search Web Service with PHP 5
  • Using the Yahoo! Web Search Service with PHP 5
  • Implementing the Image Search Service in PHP 5
  • Implementing the Yahoo! Image Search Service with PHP 5

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
     
    ADVERTISEMENT

    The Web Buyer's Guide is your best source for white papers on a wide range of IT products and services. This Week's Featured White Papers: Protecting Web Applications from Attack and Misuse by Citrix Systems

    Implementing Yahoo Image Search Web Service with PHP 5 - Using the Yahoo! Web Search Service with PHP 5
    (Page 2 of 4 )

    As you may have noticed, in many of my articles on PHP web development I like to reintroduce previous hands-on examples of how to perform a certain task with this great server-side scripting language. And this one won’t be an exception to the rule. Before I provide you with concrete code samples regarding the implementation of Yahoo!’s video and image web search services with PHP 5, I'm going to list the complete source code of the example that you learned in the previous tutorial. As you'll probably recall, it showed you how to invoke the traditional Yahoo! Search Service.

    So having said this, please take some time to look at the following code sample, which queries the web service in question with the search term “Madonna” and at the end, displays the returned results by using a few basic (X)HTML tags:

    try{

    $request='http://api.search.yahoo.com/WebSearchService/V1/webSearch?
    appid=Your-AP-ID&query=Madonna&results=2&output=php';

    // trigger the http request

    if(!$results=file_get_contents($request)){

    throw new Exception('Error requesting Yahoo! Web service');

    }

    $results=unserialize($results);

    foreach($results[ResultSet][Result] as $result){

    echo '<h2>'.$result[Title].'</h2><p>'.$result[Summary].'</p><a href="'.$result
    [Url].'">'.$result[Url].'</a>';

    }

    }

    catch(Exception $e){

    echo $e->getMessage();

    exit();

    }



    // displays the following:


    Madonna


    Official site of pop diva Madonna, with news, music, media, and fan club.

    http://www.madonna.com/


    MySpace.com - Madonna - Pop / Rock - www.myspace.com/madonna


    Madonna MySpace page with news, blog, music downloads, desktops, wallpapers, and more.

    http://www.myspace.com/madonna

    If you study closely the above practical example, you’ll see that implementing the Yahoo! Web Search Service with PHP 5 is a relatively simple process that can be tackled even if you’re a beginner at PHP programming. As shown by the previous code sample, first the script queries the mentioned service by using the corresponding application ID provided by Yahoo! along with the respective search term and the “output=php” option. Then the potential results are returned in the form of a serialized array. Pretty understandable, right?

    Next, those results are properly unserialized and then displayed on the browser via a common “foreach” PHP statement. In addition, it’s worthwhile to highlight that the web service always sends the output wrapped in a “ResultSet” array element, which can be easily parsed by utilizing some regular PHP array handling functions.

    So far, so good. At this stage you've hopefully recalled the basics for implementing the Yahoo! Web Search Service with PHP 5. Thus it’s an excellent moment to see how to apply the same business logic that you learned previously to use the respective image and video search services.

    Therefore, considering that learning how to incorporate these two useful Yahoo! web services into your PHP applications can potentially be interesting, go ahead and read the next section. I’ll be there waiting for you.

    More PHP Articles
    More By Alejandro Gervasio


       · Over this third chapter of the series, you’ll learn how to consume other helpful web...
     

       

    PHP ARTICLES

    - Comparing Files and Databases with PHP Bench...
    - Setting Up a Web-Based Image Gallery
    - Using Timers to Benchmark PHP Applications
    - Benchmarking Applications with PHP
    - Setting Up a Web-Based File Manager: PHPfile...
    - Developing a Modular Class For a PHP File Up...
    - Setting Up a Web-Based File Manager: bfExplo...
    - Defining a Custom Function for File Uploader...
    - Parsing Child Nodes with the DOM XML extensi...
    - Creating an Error Handling Module for a PHP ...
    - Accessing Attributes and Cloning Nodes with ...
    - Retrieving Information on Selected Files wit...
    - Handling HTML Strings and Files with the DOM...
    - Building File Uploaders with PHP 5
    - Working with Multiple Document Nodes with th...

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway