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

       

    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 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek