phpYahoo: An Unofficial Yahoo Search API

January 30th, 2007 by jay

*updated - 2007-01-26*
phpYahoo is a class written in PHP5 that act's as a wrapper for Yahoo's! Web Search API. Methods process the response XML and return an array of data to make development easier. With this class you can search for Yahoo! Web content, Yahoo! Videos or Yahoo! Images.

This class follows a similar pattern like phpNapster class.

Demo

Code

Example Usage
Below are a few examples for using phpYahoo.

Invoking the phpYahoo Class

PHP:

  1. require_once('phpYahoo.php');
  2. $y = new phpYahoo('YAHOOAPPID');
  3.  
  4. $searchtext= $_GET['searchtext'];

Yahoo! Web Search

PHP:

  1. $results_web = $y->searchWeb($searchtext,20)//search text and number of results MAX:50
  2.  
  3. foreach($results_web as $result) { 
  4.     $html_web .= "<p style='background:".$bgcolor.";'>\n";   
  5.          
  6.         //display a link to the search item result
  7.     $html_web .= "<a href='".$result['clickUrl']."' title='".$result['displayUrl']."'>".$result['title']."</a>";
  8.     $html_web .= "<br>";
  9.          
  10.         //display the summary
  11.     $html_web .= $result['summary'];
  12.     $html_web .= "<br>";
  13.     $html_web .= "</p>\n";   
  14.     $count++;   
  15. }         
  16. echo $html_web;

Yahoo! Video Search

PHP:

  1. $results_web = $y->searchVideos($searchtext,20)//search text and number of results MAX:50
  2.  
  3. foreach($results_video as $result) { 
  4.     $html_video .= "<p>\n";  
  5.     $html_video .= "<a href='".$result['clickUrl']."' title='".$result['displayUrl']."'>".$result['title']."</a>";
  6.     $html_video .= "<br>";
  7.     $html_video .= $result['summary'];
  8.     $html_video .= "<br>";
  9.  
  10.         //display a thumbnail of the video with a link
  11.     $html_video .= "<a href='".$result['url']."' title='".$result['title']."'><img src='".$result['thumbnail']."'></a>";
  12.     $html_video .= "<br>";
  13.     $html_video .= "</p>\n";           
  14. }      
  15. echo $html_video ;

Yahoo! Image Search

PHP:

  1. $results_images = $y->searchImages($searchtext,20);
  2.        
  3. $html_images .= "<p>\n";   
  4. $html_images .= "<table><tr valign=top>\n"
  5. $i=0;
  6. foreach($results_images as $result) { 
  7.     $html_images .= "<td width='23%' align='center'>\n";       
  8.     $html_images .= "<a href='".$result['url']."' title='".$result['title']."'><img src='".$result['thumbnail']."' border='0'></a>";
  9.     $html_images .= "<br>";
  10.            
  11.     $html_images .= "</td>\n"
  12.     $i++;   
  13.     if($i==3) {
  14.         $html_images .= "</tr><tr valign=top>";
  15.         $i=0;
  16.     }      
  17. }
  18. $html_images .= "</table></p>\n";   
  19.  
  20. echo    $html_images;

Posted in phpYahoo |

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.