Home > Programming > How to search yahoo images with PHP.

How to search yahoo images with PHP.

December 10th, 2009 Jimmy Leave a comment Go to comments

The following code is a basic example of how to use the Yahoo search API. An array of objects is returned containing the search results letting you create dynamic scripts to show images. This code could be used to make a simple plug-in for WordPress to show images based on tags in your posts or you can use it in any PHP script.

<?php

$keyword =”Cool+Wallpaper”;

$request = ‘http://search.yahooapis.com/ImageSearchService/V1/imageSearch?appid=YahooDemo&query=’ . $keyword . ‘&results=12&output=php’;

$response = file_get_contents($request);

$phpobj = unserialize($response);

foreach($phpobj['ResultSet']['Result'] as $imgobj)

{

echo $imgobj['Thumbnail']['Url']; //The URL for the thumbnail

echo $imgobj['ClickUrl']; //The URL for the full image;

echo $imgobj['Width']; //The full picture width; ( Do I need to post the height example?  )

}

?>

Digg: DIGG ME
  1. No comments yet.
  1. No trackbacks yet.