Home arrow PHP arrow Page 4 - Using Yahoo! Web Services with PHP 5

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

In the last few years, the utilization of different web services has become very popular with web developers. This growing trend owes a lot to the development of so-called mashup applications, where many of these web services are put to work seamlessly in conjunction, generally using a server-side programming language that is common to all of them. This article, the first in a six-part series, will get you started with using the Yahoo! Developer Framework in PHP 5 to build some useful web services.

  1. Using Yahoo! Web Services with PHP 5
  2. Getting started using the Yahoo! Web Search services
  3. Implementing the Yahoo! Video Search Service with PHP 5
  4. Querying the Yahoo! Image Search Service with PHP 5
By: Alejandro Gervasio
Rating: starstarstarstarstar / 9
January 08, 2008

print this article



As I explained in the section that you just read, the last hands-on example that Iím going to show you in this article will be aimed at demonstrating how to query the Yahoo! Image Search Service directly from inside a simple PHP 5 script.

Logically, this procedure is nearly identical to the one discussed in the prior section. Its main difference rests on the URL where the web service in question has to be queried. But let me go straight to the point and show you how to use this helpful Yahoo! Service with PHP 5. Take a look at the following code sample:


// example using Yahoo! Image Search Web Service - search results are displayed in raw XML format


// trigger the http request


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


// display the results in XML format


echo $results;


catch(Exception $e){

echo $e->getMessage();



// displays the following


<ResultSet xsi:schemaLocation="urn:yahoo:srchmi
ImageSearchResponse.xsd" totalResultsAvailable="684079"
totalResultsReturned="2" firstResultPosition="1">



<Summary>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</Summary>
















<Summary>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</Summary>
















ws05.search.scd.yahoo.com uncompressed/chunked Wed Oct 17
08:02:55 PDT 2007


As demonstrated above, using the Yahoo! Image Search Service with PHP 5 requires practically the same steps that you learned when using other web services. In this case, the pertinent results are retrieved by using the same ďfile_get_contents()Ē PHP native function that you saw before, and are also displayed on the browser in raw XML format.

Finally, taking into account that all of the code samples included in this tutorial might be the first ones that you learned concerning the implementation of the most common web services offered by Yahoo! with PHP 5, I suggest you to develop your own test examples to acquire a more solid background in this useful and interesting topic.

Final thoughts

Thatís it for now. In this initial installment of the series, I showed you with some educational code samples how to query basically the four primary web search services provided by Yahoo! directly with PHP 5. As you saw earlier, in every case the corresponding search results were outputted in XML, but this is only momentary.

Iím saying this because in the next tutorial of the series Iím going to teach you how to utilize all these Yahoo! APIs to work specifically with PHP, and display the results returned by a given search query in the form of serialized arrays.

Now that you know what the upcoming part will be about, you wonít want to miss it!

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

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


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