Home arrow PHP arrow Page 4 - Implementing Yahoo Image Search Web Service with PHP 5

Implementing the Yahoo! Image Search Service with PHP 5 - PHP

Welcome to the third installment of the series “Using Yahoo! Web Services with PHP 5.” If you’re a PHP programmer who wants to learn how to incorporate the useful web services offered by Yahoo, then this series of articles might be what you’re looking for. You’ll find numerous code samples to help you start using these popular web services within your own PHP 5 applications.

TABLE OF CONTENTS:
  1. Implementing Yahoo Image Search Web Service with PHP 5
  2. Using the Yahoo! Web Search Service with PHP 5
  3. Implementing the Image Search Service in PHP 5
  4. Implementing the Yahoo! Image Search Service with PHP 5
By: Alejandro Gervasio
Rating: starstarstarstarstar / 3
January 29, 2008

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

If you’ve been paying attention to the approach that I followed in earlier sections of this article to implement with PHP 5 some of the most popular web services provided by Yahoo!, then it’s quite probable that you'll find the following example very easy to grasp. It demonstrates in a friendly fashion how to use the pertinent image search service by using the same script that you learned previously.

Invoking the aforementioned Yahoo! web service through PHP requires coding only a simple PHP code snippet, like the one that follows:

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


try{

$request='http://search.yahooapis.com/ImageSearchService/V1/imageSearch?
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 script looks very similar to the one that I used to query the Yahoo! Video Search Service, so I won’t give you boring explanations of how it works. The only thing you need to notice is how the corresponding image results are extracted from the returned serialized array, something that, at this point, should also be familiar to you. Besides, with the purpose of completing the previous explanation on using the popular Yahoo! Image Search Service with PHP 5, below I listed the pair of results produced by the prior script. Here they are:

// search results displayed by the previous script are as follows


Madonna_vogue.jpg


Madonna_3.jpg 30-Apr-2005 14:34 23k Madonna_9.jpg 30-Apr-2005 14:34 23k
Madonna_vogue.jpg 30-Apr-2005 14:35 22k Madonna_13.jpg 30-Apr-2005 14:34
22k


http://www.multinet.no/~jonarne/Hjemmesia/Favorittartister/madonna/
Madonna_vogue.jpg

madonna_90563a.jpg


ANGRER: Madonna spiller gjerne pa sex for a provosere, men angrer pa boken Sex.- Jeg lurer stadig pa hva som motiverte meg til a lage den, sier hun om sin vagale bok, Sex , som vakte


http://pub.tv2.no/multimedia/TV2/archive/00090/madonna_90563a.jpg

At this stage I provided enough material for you to get started using the most relevant web services offered by Yahoo! within your own PHP 5 applications. So I recommend that you practice with these code samples to expand your skills in utilizing these handy services with PHP 5.

Final thoughts

In this third part of the series I showed you how to work with serialized PHP arrays and how to quickly parse the results returned by the Yahoo! Video and Image Search services -- certainly a process that can be tackled with minor hassles.

Nonetheless, this instructive journey hasn’t ended yet, since in the next article I’m going to show you how to invoke all of those helpful web services by defining some simple, efficient custom PHP functions. This could be useful if you’re using a procedural approach to develop your PHP applications.

Now that you’ve been alerted to the topics that will be covered in the upcoming tutorial, you don’t have any excuses to miss it!



 
 
>>> More PHP Articles          >>> More By Alejandro Gervasio
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: