PHP
  Home arrow PHP arrow Page 3 - Implementing Yahoo Image Search Web Service with PHP 5
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
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? 
Google.com  
PHP

Implementing Yahoo Image Search Web Service with PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 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:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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


    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
     

       

    PHP ARTICLES

    - Implementing Factory Methods in PHP 5
    - Merging a File Split for FTP Upload using PHP
    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek