PHP
  Home arrow PHP arrow Page 3 - 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 
 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

    Ziff Davis Enterprise Virtual Tradeshows: Hot Topics, Cutting Edge Technology, Real-time Networking among IT Professionals. Learn more

    Implementing Yahoo Image Search Web Service with PHP 5 - Implementing the Image Search Service in PHP 5
    (Page 3 of 4 )

    As I explained in the section that you just read, Yahoo! also provides PHP developers with a couple of powerful APIs that can be used within a given PHP 5 application to implement the popular video and image web search services with minor difficulties. As you’ll see in a few moments, these services can be easily queried by implementing practically the same programming logic that you learned in previous examples on this tutorial. This means that you shouldn’t have major problems putting the services to work for you.

    But it’s time to move on from this boring theory since I assume you’re hungry to see some concrete code samples, right? Thus, I’m going to begin by demonstrating how to invoke the helpful Yahoo! Video Search Service from a primitive PHP 5 script. It also will be capable of displaying the corresponding results in (X)HTML format.

    Now that I have explained how this brand new hands-on example is going to work, please pay attention to the following code sample to see the Yahoo! video search service in action:

    // example using Yahoo! Video Search Service - results are displayed in a basic (X)HTML format utilizing a procedural approach


    try{

    $request='http://search.yahooapis.com/VideoSearchService/V1/videoSearch?
    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><p><img
    src="'.$result[Thumbnail][Url].'" width="'.$result[Thumbnail][Width].'"
    height="'.$result[Thumbnail][Height].'" /></p><a href="'.$result[Url].'">'.$result
    [Url].'</a>';

    }

    }

    catch(Exception $e){

    echo $e->getMessage();

    exit();

    }

    As you can see, the above PHP 5 script has a signature that’s very similar to the one that I defined to query the Yahoo! Web Search. However, there are some slight differences here, because in this particular case I’m using the Yahoo API to implement its helpful video search service. This means that the URL where the respective HTTP request is triggered is obviously distinct.

    However, the rest of the script remains practically the same. The search results are first returned as a serialized PHP array and then displayed on the browser by using some basic (X)HTML tags. Besides, you should pay careful attention to the way that these results are extracted from the aforementioned array, since in this case I’m only interested in showing the pertinent titles, a brief summary on the retrieved video files, and the respective links.

    Also, to complement the previous explanation, below I included an unformatted version of these search results, so you can grasp more clearly how the previous script functions:

    // the following search results are displayed


    madonna_2004_montage.wmv


    Interviews, news footage and tour clips from New York and Paris....here's hoping 2005 is just as busy! Right Click And Save Target As Madonna's 2004 Movie Montage (WMV) - 7:44 - 21.8Mb Noticias madonna - Noticias madonna - Noticias madonna -


    http://madonnalicious.com/downloads/madonna_2004_montage.wmv

    madonna_earlscourt_190804.wmv


    http://www.madonnalicious.com/downloads/madonna_gelredome_090904.wmv
    madonna 9sep 2004 http://www.madonnalicious.com/downloads/madonna_earlscourt_190804.wmv
    http://www.madonnalicious.com/downloads/madonna_earlscourt_dtm_

    190804.wmv

    http://www.madonnalicious.com/downloads/madonna_earlscourt_190804.wmv

    Indeed, after analyzing the prior hands-on example, you’ll have to agree with me that calling the powerful Yahoo! Image Search Service from your own PHP application is a straightforward process that can be tackled pretty effortlessly. And if you still have your doubts as to my claims, test the previous example on your web server (don’t forget to get an application ID first) and you’ll be amazed at how neatly it works!

    I think it’s time to move on, since I plan to show you yet another practical example focused primarily on demonstrating how to implement the Yahoo! Image Search Service in PHP 5. But as you might have guessed, this topic will be covered in detail in the upcoming section, so click on the link below and keep reading.

    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...




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