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? // 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 } } 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 http://www.multinet.no/~jonarne/Hjemmesia/Favorittartister/madonna/ 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!
blog comments powered by Disqus |
|
|
|
|
|
|
|